Size of array

Posted by Margamchakradhar31 under C# on 7/20/2009 | Views : 4600 | Status : [Member] | Replies : 2
what is the default size of ArrayList and Array




Responses

Posted by: Raja on: 7/20/2009 [Member] Starter

Up
0
Down
There is no default size of either Array or ArrayList.

An ArrayList is the dynamic array that can grow as you keep adding elements into it.

ArrayList list = new ArrayList();

list.Add(2) // keep adding and it will grow
.

An array has limitation of number of elements you specify at the time of defining it. The max size of Array can be int.MaxSize.

string[] s = new string[2]; // you are limited to add only two elements.

s[0] = "A";
s[1] = "B";


Hope this helps.

Regards,
Raja, USA

Margamchakradhar31, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saantosh on: 9/2/2009 [Member] Starter

Up
0
Down
--> No default size of either Array or ArrayList
-->ArrayList class implements IList interface
There are Many Advantages
1. Its Provide Commaon method such as : add,insert,append, remove, replace etc.
2. capacity are increased when objects are added .
3. no restriction added to an arraylist , you can add first objects is integer,secound object string and you can also added user define object in array list. you can sey that it will be added Heterogeneous data.

eg For Adding Data to Array List

Dim arrList as new ArrayList
arrList .add("A")
arrList .add("C")
arrList .add("B")
arrList .add("1")

You Can Sort The Data
arrList .Sort
arrList .Reverse

Read Data for Index Basis
dim a as string=arrList.Item(3)


Thanks & Regards
Santosh Kumar
http://www.operativesystems.com

Margamchakradhar31, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response