3 Replies - 306 Views - Last Post: 29 September 2013 - 02:16 PM Rate Topic: -----

#1 dreamincodehamza  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: -12
  • View blog
  • Posts: 329
  • Joined: 12-September 08

C# collections

Posted 28 September 2013 - 05:35 PM

Need help in understanding further more on arraylist and list done some search work and done some work.

Difference between list and arrayLIst in c#

List ArrayList
it store only Type of object, Its store Array of Object.

specify the object type No Need to specify the object type,can store anything
which is mentioning while initializing List object. example
ArrayList aryList= new ArrayList();
example:
List<int>
List<float>
List<double>
List<char>


Please let me know further important difference so i can make my self understand better,
thank you

Is This A Good Question/Topic? 0
  • +

Replies To: C# collections

#2 Momerath  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 995
  • View blog
  • Posts: 2,383
  • Joined: 04-October 09

Re: C# collections

Posted 28 September 2013 - 09:36 PM

When you use an ArrayList you'll need to cast the object returned back into whatever class it is. Example
ArrayList myArrayList = new ArrayList();
myArrayList.Add(new Dictionary<String, int>);
Dictionary<String, int> myDictionary = (Dictionary<String, int>)myArrayList[0];


List<T> can hold more than one type of object, as long as all the objects implement or inherit from the same type as specified in the List. Example
List<ICollection> myList = new List<ICollection>();
myList.Add(new List<double>());
myList.Add(new List<int>());
myList.Add(new Dictionary<int, double>());
myList.Add(new ArrayList());

This post has been edited by Momerath: 28 September 2013 - 09:37 PM

Was This Post Helpful? 2
  • +
  • -

#3 dreamincodehamza  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: -12
  • View blog
  • Posts: 329
  • Joined: 12-September 08

Re: C# collections

Posted 29 September 2013 - 12:08 PM

View PostMomerath, on 28 September 2013 - 09:36 PM, said:

When you use an ArrayList you'll need to cast the object returned back into whatever class it is. Example
ArrayList myArrayList = new ArrayList();
myArrayList.Add(new Dictionary<String, int>);
Dictionary<String, int> myDictionary = (Dictionary<String, int>)myArrayList[0];


List<T> can hold more than one type of object, as long as all the objects implement or inherit from the same type as specified in the List. Example
List<ICollection> myList = new List<ICollection>();
myList.Add(new List<double>());
myList.Add(new List<int>());
myList.Add(new Dictionary<int, double>());
myList.Add(new ArrayList());


thanks for this difference
please have a look at this page http://shubhankupadh...aylist-and.html
Are these differences are correct and valid for remembering??
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: C# collections

Posted 29 September 2013 - 02:16 PM

View PostMomerath, on 29 September 2013 - 05:36 AM, said:

List<T> can hold more than one type of object, as long as all the objects implement or inherit from the same type as specified in the List. Example
List<ICollection> myList = new List<ICollection>();
myList.Add(new List<double>());
myList.Add(new List<int>());
myList.Add(new Dictionary<int, double>());
myList.Add(new ArrayList());


Remember though if you do this you'll only have access the to ICollection implementation of the object in the list. For the parts that are specific to the stored type, you need to cast it back to that type.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1