System.Generic.List<BaseBlock> BlockList = new System.Generic.List<BaseBlock>();
BaseBlock
is an abstract class. Later in the program I add some objects to the list. Knowing the index of the object, how can I get the specific (not abstract) type / class of it?
答案 0 :(得分:1)
Knowing the index of the object, how can I get the specific (not abstract) type / class of it?
To find the actual type of the object at index i
use
Type t = BlockList[i].GetType();
GetType
gives you the actual type of an object, regardless of the type of variable or container it's in.