Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
2.60/5 (4 votes)
See more:
Difference b/w array and arraylist in c#
Posted
Comments
[no name] 30-Nov-11 23:25pm    
google?
Smithers-Jones 1-Dec-11 4:44am    
Not a question, not even a full sentence, no effort, lazy bum. Reported.
CodeHawkz 20-Sep-12 2:58am    
lol :D I feel your frustration. The number of people who don't know to form a question properly is too damn high :\

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.
 
Share this answer
 
Extracted from here :
http://stackoverflow.com/questions/128636/net-data-structures-arraylist-list-hashtable-dictionary-sortedlist-sorted[^]



Array - represents an old-school memory array - kind of like a alias for a normal type[] array. Can enumerate. Can't grow automatically. I would assume very fast insertion and retriv. speed.

ArrayList - automatically growing array. Adds more overhead. Can enum., probably slower than a normal array but still pretty fast. These are used a lot in .NET

List - one of my favs - can be used with generics, so you can have a strongly typed array, e.g. List<string>. Other than that, acts very much like ArrayList.

Hashtable - plain old hashtable. O(1) to O(n) worst case. Can enumerate the value and keys properties, and do key/val pairs.

Dictionary - same as above only strongly typed via generics, such as Dictionary<string,>

SortedList - a sorted generic list. Slowed on insertion since it has to figure out where to put things. Can enum., probably the same on retrieval since it doesn't have to resort, but deletion will be slower than a plain old list.
 
Share this answer
 
-Array is of fixed size but Arraylist is a datastructure which can dynamically grow and shrink.

-Array is created in stack memory where Arraylist is created and stored in heap area.
 
Share this answer
 
 
Share this answer
 
class Program
{
static void Main()
{
//
// Create an ArrayList and add three elements.
//
ArrayList list = new ArrayList();
list.Add("One");
list.Add("Two");
list.Add("Three");
}
}
class program
{
static void Main(string[] args)
{
List<string> lstString = new List<string>();

lstString.Add("ABCD");

lstString.Add(new Program()); //Compiler error

lstString.Add(4); // Compiler Error





foreach (object o in lstString)

{

Console.WriteLine(o.ToString());

}
}
}
 
Share this answer
 
Comments
[no name] 10-Aug-13 13:20pm    
And how is this any kind of an answer to this ancient over-the-hill not-even-a-question?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900