Accessing a static property of a child in a parent method

前端 未结 9 1320
孤城傲影
孤城傲影 2021-01-21 06:07

Say I have the following code:

class Parent
{

    static string MyField = \"ParentField\";

    public virtual string DoSomething()
    {
        return MyField         


        
9条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-21 06:53

    Use a static property instead of a static variable. Then you can override the property in the child class instead of creating a "new" field.

提交回复
热议问题