Tuesday, 29 January 2013

Array in C sharp


By on 03:27

Arrays in C Sharp:-Array is the collection of similar type of element.

Declaration of Array in C#:-

[data type][[]][array name]=[no. of array element]

Example:-int[]ar=[3,5,6,7,8];

Array index always start from 0 to n-1.Array can be access randomly.

System.Array Class:-The array methods are as follows:-

1)Clear()  2)CopyTo()  3)GetLength()  4)Length()  5)SetValue()  6)Reverse()  7)Sort()  8)Add()  9)CopyTo()  10)Insert()  11)Remove()  12)RemoveAt()  13)Sort()  14)Capacity()  15)Count()  etc.

Program of C# using Array:-


int[]ar=[2,5,6,3,1,4,88];

int s,t=0,1;
double ar;
s=ar.length;
for(i=0;i<s;i++)
{
t=t+ar[i];
Console.Writeline(ar[i]);
}
ar=t/s;
Console.Writeline("Average="+ar);
Console.Read();
}
}
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...