I need to go through List. I do not know in advance what type of element List contains the List I get as an object.
void anyMethod(object listData, Func<object, string> callback)
{
foreach (object item in (List<object>)data)
{
string value = callback(item);
doSomething(value)
}
};
...
List<MyObject> myList = something();
anyMethod(myList, obj => (MyObject)obj.Name)
...
List<AnotherObject> myList = somethingAnother();
anyMethod(myList, obj => (AnotherObject)obj.foo + (AnotherObject)obj.bar)
...
I need something he does as DropDownList when the process DataSource.
Thanks for your help.
You could try this:
However, if you actually call this method with a strongly typed list (such as
List<YourType>) you can use generics better:which is a lot cleaner.