F
Frank
Hello,
I don't know how to do the following.
In a method I get a parameter with type object. These can be about 10
different types and I want to store the object in a list with the correct
type (so, not type object, but type A or B or C). I could use a switch on
gettype and then do a cast and put it in the list. But if new types are
added I have to change this method and I am too lazy to do that. I need
something like:
list.add((gettype(object))object)
The '(gettype(object))' is meant as a cast, but this is not possible in c#.
How can I add the correct type in a generic way? So I don't need to change
anything if a new type is created.
Thanks
Frank
I don't know how to do the following.
In a method I get a parameter with type object. These can be about 10
different types and I want to store the object in a list with the correct
type (so, not type object, but type A or B or C). I could use a switch on
gettype and then do a cast and put it in the list. But if new types are
added I have to change this method and I am too lazy to do that. I need
something like:
list.add((gettype(object))object)
The '(gettype(object))' is meant as a cast, but this is not possible in c#.
How can I add the correct type in a generic way? So I don't need to change
anything if a new type is created.
Thanks
Frank