Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve Object from arraylist in c#

Tags:

c#

How to retrieve Object and its member from arraylist in c#.

like image 718
SunilRai86 Avatar asked Jun 24 '10 13:06

SunilRai86


2 Answers

You mean like this?

ArrayList list = new ArrayList();
YourObject myObject = new YourObject();

list.Add(myObject);    

YourObject obj = (YourObject)list[0];

To loop through:

foreach(object o in list)
{
   YourObject myObject = (YourObject)o;  
  .......
}

Information on ArrayList

like image 113
kemiller2002 Avatar answered Oct 19 '22 13:10

kemiller2002


    object[] anArray = arrayListObject.ToArray();
    for(int i = 0; i < anArray.Length; i++)
       Console.WriteLine(((MyType)anArray[i]).PropertyName); // cast type MyType onto object instance, then retrieve attribute
like image 23
P.Brian.Mackey Avatar answered Oct 19 '22 13:10

P.Brian.Mackey