KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to make a generic method that can accept any object, in which, even the object is List<AnyClass> . Something like: public static void MyMethod(object _anyObject) { } So in my method it accept the parameter as Object, then I will determine what to do by their type to do So when I know that's a List type, I want to convert that Object back to List<AnyClass> , iternate each object and their propertie I tried to do: List<object> ObjectList = object as List<object>; But it will return null , because the object originally is List<AnyClass> Thanks in advance ================ Edit: Sorry, seems like I haven't make it clear, because I simplifed the problem... I means the Object might be: _anyObject = List<Class1> _anyObject = Class2 _anyObject = DataSet _anyObject = AnyClass _anyObject = List<object> So say, the user can even put in a List<object> , but each of the object in that list can be different class..That's why I can't use <T> . The original of my problem is: public static void MyMethod(List<object> _anyList) { } Then I don't care what they put into the list, even the object in the list contains another object list...
Tags (comma-separated)
Save Edits
Cancel