Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET C# Lists Which and When?

Tags:

c#

list

asp.net

In C# There seem to be quite a few different lists. Off the top of my head I was able to come up with a couple, however I'm sure there are many more.

List<String> Types = new List<String>();
ArrayList Types2 = new ArrayList();
LinkedList<String> Types4 = new LinkedList<String>();

My question is when is it beneficial to use one over the other?

More specifically I am returning lists of unknown size from functions and I was wondering if there is a particular list that was better at this.

like image 373
corymathews Avatar asked Aug 11 '09 14:08

corymathews


1 Answers

List<String> Types = new List<String>();
LinkedList<String> Types4 = new LinkedList<String>();

are generic lists, i.e. you define the data type that would go in there which decreased boxing and un-boxing.

for difference in list vs linklist, see this --> When should I use a List vs a LinkedList

ArrayList is a non-generic collection, which can be used to store any type of data type.

like image 168
Bhaskar Avatar answered Oct 05 '22 23:10

Bhaskar