Accessing a property of derived class from the base class in C#

前端 未结 7 646
夕颜
夕颜 2020-12-03 06:06

In C#, what is the best way to access a property of the derived class when the generic list contains just the base class.

public class ClassA : BaseClass
{
          


        
7条回答
  •  死守一世寂寞
    2020-12-03 06:22

    The whole premise doesn't make sense - what would PropertyB be for the a instance?

    You can do this if you do manual runtime type checking (inst is Foo), and then cast to the type with the property you want.

提交回复
热议问题