C# .NET - Different between array and array list of collection
Asked By dotnet chd
28-Oct-11 02:56 AM
What is Different between array and array list of collection in .Net
Please give some examples
James H replied to dotnet chd

Different between array and array list of collection
Array is a primitive data structure, which stores the values in indexed format.
ArrayList is a mre like a vector. (A re-sizeable array). It is a collection and stores any value as an object.
If you know the size, the use array, if not try array list (only for learning purpose, later you'll know about some more advanced collections which will save you time and memory)
1)An array can be of any data type and contain one data type while array list can contain any data type in the form of the object.
2)With array you can not dynamically increase or decrease the size of array dynamically. You must the define the size of the array. You can change the size of the array with redim statement but still you have to define type. While with array list you can make list of any sizes. When a element or object is added to array list it size is automatically increase the capacity of the array list.
3)once you delete the item in array it kept that one as empty like a[2]="" but in case of arraylist a[3]index occupies the position of a[2] and also if you try to insert a[2] value array will throw error if any items reside inside but in case of arraylist a[2] is inserted in same position but at the same time position of a[2] become a[3] if there is already an item exists
Vickey F replied to dotnet chd
Arrays
---------
* Array is in the System namespace
* The capacity of an Array is fixed
* An Array can have multiple dimensions
* Declarations of Array
string[] arr = new string[];
ArrayList()
------------
* ArrayList is in the System.Collections namespace
* ArrayList can increase and decrease size dynamically
* ArrayList always has exactly one dimension
* Declaration of ArrayList
ArrayList arrlst = new ArrayList();
hope it will help u.
Anoop S replied to dotnet chd
Basic difference is that arrays are of fixed size. Whereas an ArrayList implements the list data structure and can dynamically grow. While arrays would be more performant that a list, a list would be far more flexible since you don't need to know the required size initially.
We can access elements in a Arraylist randomly and in LinkedList we cannot(means for accessing an element we have traverse from first elemet in Linkedlist.
Riley K replied to dotnet chd
|
ARRAY
|
ARRAYLIST
|
|
1.
|
Char[] vowel=new Char[];
|
ArrayList a_list=new ArrayList();
|
|
2.
|
Array is in the http://www.dotnetspark.com/kb/90-difference-between-array-and-arraylist.aspx# namespace
|
ArrayList is in the System.Collectionsnamespace.
|
|
3.
|
The capacity of an Array is fixed
|
ArrayList can increase and decrease size dynamically
|
|
4.
|
An Array is a collection of similar items
|
ArrayList can hold item of different types
|
|
5.
|
An Array can have multiple dimensions
|
ArrayList always has exactly one dimension
|
|
|
Regards
what is the difference between array and arraylist Hi to All, what is the difference between array and arraylist what is the difference between array and list. Arrays - -- -- -- -- * Array is in the System namespace * The capacity of an Array is fixed * An Array can have multiple dimensions * Declarations of Array string[] arr = new string[]; ArrayList() - -- -- -- -- -- - * ArrayList is in
to have the client to send an object Public Class Order Public OrderID As New ArrayList ' array list of integers Public OrderXML As New ArrayList 'array list of string Public LineNumber As New ArrayList 'array list of integer Public Attachment As New ArrayList ' array list of byte End Class the
and programmatically getting all the rows and columns, but I am transfering the data into ArrayList / Array instead of data table and then From ArrayList / Array I am writing to notepad / tsv files. so while exporting more rows ( more than 2000 rows excelFile + "_" + selectedSheetName + ".tsv"; if (System.IO.Directory.Exists(fileDir)) { System.IO.Directory.CreateDirectory(fileDir); } Array ArExcelData = excelExportDataBlock(excelFile, selectedSheetName); sw.Write(" \ t", check); sw.Write(" \ r \ n"); sw.Close(); file
change Value in ArrayList in ArrayList pls help me ArrayList arrContain = new ArrayList(); ArrayList data = new ArrayList(); data.Add("a"); data.Add("b"); data.Add("c"); data.Add("d"); arrContain.Add(data); data = new ArrayList(); data.Add("aa"); data.Add("bb"); data.Add("cc"); data.Add("dd"); data.Add("ee arrContain.Add(data); data = new ArrayList(); data.Add("11"); data.Add("22"); data.Add("33"); data.Add("44"); data.Add("55