ArrayList is non-generic collection and List is a specific type collection type. List Collection accepts only a specific type of data only.
ArrayList arrlist=new ArrList();
ArrayList arrlist = new ArrayList();
arrlist.Add(10);
arrlist.Add("dfasdfa")
arrlist ---acceptsà any type of data like int ,string,double….and
arrlist(new string[] {“adfasd”,”dfasdf”,”dfasd”});--any type. But in comes to
List<string> strlist = new List<string>();
strlist.Add("anand");
strlist.Add("balu");
strlist.Add("charan");
strlist.Add("rohit");
List<T> type it will only accepts a specific data,That is T[int,doubl,foloat,…employee] type.
ArrayList accepts any type which implements ICollection. As obsely which accepts array also it can be int array,string array,float arry.
Ok as well ArrayList implements IList so which accepts List Collection
Also as argument and prepares ArrayList type of collection.
ListCollection is strong Collection
ArrayList is Weak Collection Accorinding to performance. But is any where required to convert List Collection type to ArrayList Collection.
We have to Choose Adapter(IList item) method.
Ex:
List<string> strlist = new List<string>();
strlist.Add("anand");
strlist.Add("balu");
strlist.Add("charan");
strlist.Add("rohit");
ArrayList listtoarray = new ArrayList();
listtoarray = ArrayList.Adapter(strlist);
Console.WriteLine(listtoarray.Count);
Adapter is a static method which accepts a collection which implements IList Interface.
Adapter method takes any List like List<int>,List<string>,List<Employee>…ect
As well as
IList interface defines an indexer
object this[int index] { get; set; };
then ArrayList as well as any List<T> types also can we can easily indexing them any element.
Ex:
ArrayList arrlist = new ArrayList();
arrlist.Add("kasi");
arrlist.Add(10);
arrlist.Add(10.52);
arrlist.Add(DateTime.Now);
Console.WriteLine(arrlist[0]);
Console.WriteLine(arrlist[1]);
Console.WriteLine(arrlist[2]);
Console.WriteLine(arrlist[3]);
ArrayList Elements are indexed and
List<string> strlist = new List<string>();
strlist.Add("anand");
strlist.Add("balu");
strlist.Add("charan");
strlist.Add("rohit");
Console.WriteLine(strlist[0]);
Console.WriteLine(strlist[1]);
Console.WriteLine(strlist[2]);
Console.WriteLine(strlist[3]);
No comments:
Post a Comment