Ciarán
Ciarán

Reputation: 773

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 objects 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

Upvotes: 0

Views: 438

Answers (2)

Yuriy Faktorovich
Yuriy Faktorovich

Reputation: 68747

((CTile)CObjList[0][0][0]).titleImageId

or

(CObjList[0][0][0] as CTile).titleImageId

Upvotes: 2

Sander Rijken
Sander Rijken

Reputation: 21615

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

Upvotes: 1

Related Questions