I am calling a method that returns a List variable that contains a c# Anonymous Type objects. For example:
List
You cannot do this with anonymous types. Just create a Contact class/struct and use that.
List list = new List();
foreach ( Contact c in allContacts ) {
list.Add( c );
}
Then you can do this:
foreach ( var o in list ) {
Console.WriteLine( o.ContactID );
}
...or this:
foreach ( object o in list ) {
Console.WriteLine( ((Contact)o).ContactID ); //Gives intellisense
}
Of course you should in that case just do create a Contact list instead of an object list:
List list = new List();
foreach ( Contact c in allContacts ) {
list.Add( c );
}
EDIT: Missed essential part of the question. Now fixed.
EDIT: Changed answer yet again. See above.