Accessing values of an object!

Hi,

I'm facing a small problem. It would have been great if someone could provide me with the solution. I have a function that returns an object. My code is as follows.

object obj;
obj = snap.GetList();

Now when I take a quickwatch of obj.It shows me the values as obj[0]="a",obj[1]="b" and so on, which means obj contains the values. But it does not allow me to access the values as

string str = obj[0];

I also tried the following:

foreach(object o in obj)
{
 str = o;
}

But it gives me the following error:

foreach statement cannot operate on variables of type 'object' because 'object' does not contain a definition for 'GetEnumerator', or it is inaccessible.


Can I have a solution to access the values in the variable obj.

Thanks & Regards,
Frenz



Answer this question

Accessing values of an object!

  • Tryin2Bgood

    try this:

    IList list = snap.GetList();
    foreach(string s in list)
    {
    //whatever
    }


    next time, try to post on the proper sections..., by the way, you're messing up your data types


  • Accessing values of an object!