首页 新闻 会员 周边

关于在 vista,Win7上属性重写的问题

0
悬赏园豆:50 [已关闭问题]

我在父类写了一个属性

        private string m_Text = "abc";
        public virtual string Text
        {
            get { return m_Text; }
            set { m_Text = value; }
        }

在子类重写

        public override string Text
        {
            set
            {
                base.Text = value;
            }
        }

我在其他类中调用

            Child child = new Child();
            MessageBox.Show(child.Text)

这时候,我在除vista,Win7的系统上测试,都可以正常显示Text的值。但是在vista,Win7测试,具体跟踪的时候,查看Text的值,会出现cannot be used in this context because it lacks the get accessor。但是执行是没问题的。不知道是什么原因,Anyone can help me?

问题补充: 没人知道?
Hayne的主页 Hayne | 初学一级 | 园豆:5
提问于:2009-04-24 09:16
< >
分享
其他回答(1)
0

跟系统无关的 我不知道你在其他系统怎么会取到值,你是不是用了Parent child = new Child() ?

James.Ying | 园豆:1472 (小虾三级) | 2009-04-24 12:56
0

[更新了,见评论]

晕... override后变了只写属性...

http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx

A Base class property can be polymorphicaly overridden in a Derived class. But remember that the modifiers like virtual, override etc are using at property level, not at accessor level.  override 是在属性的级别上,不在访问器级别上。

因此能读到 Child.Text 才是怪事……

DiryBoy | 园豆:639 (小虾三级) | 2009-04-28 20:40
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册