Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET: ArrayList vs List

What is the difference between ArrayList and List in VB.NET

like image 317
MOZILLA Avatar asked Dec 13 '08 17:12

MOZILLA


2 Answers

ArrayLists are essentially deprecated as they're untyped - you need to use casts with them - and they're slower and less space efficient for value types because they require the items to be boxed.

Generic lists were introduced with .Net 2.0 and are the way to go. Often a List is better than an array, with few downsides.

As these collections are part of the .Net Base Class Library, this advice also applies to C# and to any .Net language which supports generics - it's not specific to VB.NET.

like image 132
Mike Scott Avatar answered Oct 04 '22 10:10

Mike Scott


List is a generic implementation of ArrayList. ArrayList stores all objects as System.Object which you need then cast to appropriate type. ArrayLists are heterogenous, List can store only one type of objects - that type supplied as its generic parameter.

List<string> strList; // can store only strings List<int> intList; // can store only ints ArrayList someList; // can store anything 
like image 38
arul Avatar answered Oct 04 '22 11:10

arul