从子类访问母类的属性 [英] Accessing properties of a mother class from a child class

查看:103
本文介绍了从子类访问母类的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的A类方法依赖于其中一个属性

I have class A with a method dependent on one of its properties

公共类A

{

                public string strg {get;组; } =" notstringvalue";

{
                public string strg{ get; set; } = "notstringvalue";

                public void mthd()

                public void mthd()

                {

                {

                                if(strg ==" stringvalue")

                               if ( strg == "stringvalue")

                                {                               
         

                               {                                         

                                   Console.WriteLine("B");

                               }

                               }

                }

                }

}

B类来自A,如果我这样做

Class B derives from A, If I do this

公共等级B:A

{

                strg =" stringvalue";

{
                strg = "stringvalue";

}

来自B实例(b.mthd())的mthd调用是否真的写" B" ;?如果没有,是否有解决方案?

Will a call of mthd from an instance of B ( b.mthd() ) really write "B"? If not, is there a solution?


推荐答案

是的,但你不能在B(或构造函数)的方法之外做到这一点
Yea but you cannot do that outside a method in B (or the constructor)


这篇关于从子类访问母类的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆