using System;
class MainClass
{
public static void Main()
{
try
{
int [] IntegerArray = new int [5];
IntegerArray[10] = 123;
}
catch(IndexOutOfRangeException)
{
Console.WriteLine("An invalid element index access was attempted.");
}
}
}
ASP.NET & Csharp (C#)
ASP.NET & Csharp (C#) , Here you can find my posts about .NET c# .
Catch OutOfMemoryException
using System;
class MainClass
{
public static void Main()
{
int [] LargeArray;
try
{
LargeArray = new int [2000000000];
}
catch(OutOfMemoryException)
{
Console.WriteLine("The CLR is out of memory.");
}
}
}
Call GetLength for two dimenional array
using System;
class ChessBoard {
static void Main(String[] args) {
Char[,] SquareColor = new Char[8, 8];
for (int i = 0; i < SquareColor.GetLength(0); i++) {
for (int x = 0; x < SquareColor.GetLength(1); x++) {
if ((x % 2) == 0)
if ((i % 2) == 0)
SquareColor[i, x] = 'W';
else
SquareColor[i, x] = 'B';
else
if ((i % 2) == 0)
SquareColor[i, x] = 'B';
else
SquareColor[i, x] = 'W';
}
}
for (int i = 0; i < SquareColor.GetLength(0); i++) {
for (int x = 0; x < SquareColor.GetLength(1); x++) {
Console.Write(SquareColor[i, x]);
}
Console.WriteLine();
}
}
}
[/csharp]
permission cref doc tag
// compile with: /doc:DocFileName.xml
class TestClass
{
/// <permission cref="System.Security.PermissionSet">Everyone can access this method.</permission>
public static void Test()
{
}
static void Main()
{
}
}
Use code tag to reference code
// compile with: /doc:DocFileName.xml
/// text for class TestClass
public class TestClass
{
/// <summary><c>DoWork</c> is a method in the <c>TestClass</c> class.
/// </summary>
public static void DoWork(int Int1)
{
}
/// text for Main
static void Main()
{
}
}
Summary doc tag and paramref tag
// compile with: /doc:DocFileName.xml
/// text for class TestClass
public class TestClass
{
/// <summary>DoWork is a method in the TestClass class.
/// The <paramref name="Int1"/> parameter takes a number.
/// </summary>
public static void DoWork(int Int1)
{
}
/// text for Main
static void Main()
{
}
}
value doc tag
// compile with: /doc:DocFileName.xml
/// text for class Employee
public class Employee
{
private string _name;
/// <summary>The Name property represents the employee's name.</summary>
/// <value>The Name property gets/sets the _name data member.</value>
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
}
/// text for class MainClass
public class MainClass
{
/// text for Main
static void Main()
{
}
}