Array and ArrayList in C#.Net

SharePoint deveopment training course

In this post we will discuss about array and arraylist in C#.net.

You can check my previous posts on

Delegates in C#.Net

Advantages of WCF in Asp.net 

WCF interview questions and answers.

Array:
– Arrays allow you to store a series of values that have the same data type.

– The values can be accessed by using its index number. And the index starts with 0 and the highest index is one less than the number of elements.

– Below is a string array:
string[] stringArray = new string[5];
Here new keyword is used to initialize the array.

Also you can directly put the values like below:
string[] stringArray = {“1”, “2”, “3”, “4”,”5″};

– We can access the values like below:

string value = stringArray[3];
The value will be 4;

– If you create an array, you can not resize the array.

– If you declared a interger array then only interger can be stored, if you try to initialize any other thing then it will give exception.

– Similarly you can create multidimentional array like below:

int[,] intArray = {{1, 2}, {3, 4}, {5, 6}, {7, 8},{9,10}};

ArrayList:
– ArratList supports any type of object and always allows dynamic resizing, means the size can be increased or decreased.

– Syntax to create array:
ArrayList arr = new ArrayList();

Put the value like below:
arr.Add(“Value1”);
arr.Add(“Value2”);
arr.Add(“Value3”);

And we can retrieve the value like below:
string value = Convert.ToString(arr[1]);

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →