C# Accessing Inherited members via parent class in a 3D List
Ok this is hard to explain, but here goes. I have a 3D list of objects. The objec开发者_StackOverflowts type are called CObject, another class CTile inherts CObject.
static public List<List <List <CObject>>> CObjList
= new List<List<List<CObject>>>();
Ok now lets say that the list is full of information in the correct way. (Can be see via breakpionts in the code); So I go to access an item in list like below
CObjList.[0][0][0].titleImageId
Ok titleImageId is a member of CTile, but I cant access it by using this syntax. Its public and everything. All that I can access are the members of CObject class.
I hope I have explained myself as best I can there. Thanks
((CTile)CObjList[0][0][0]).titleImageId
or
(CObjList[0][0][0] as CTile).titleImageId
Use:
CList l = CObjList[0][0][0] as CList;
if(l != null)
id = l.titleImageId
You should index the CObjList
directly, not using a dot operator
精彩评论