虚拟财产 [英] virtual properties

查看:97
本文介绍了虚拟财产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用和博学多才基类的虚方法,而不用作

  A级$虚拟财产的任何知识b $ b {
公共虚拟的ICollection< b>托{获取;集;}?
}



有人能告诉我这是什么意思


解决方案

  public虚拟的ICollection< b>道具{搞定;组; } 



平移几乎直接到:

 私人的ICollection< B> _支柱; 

公共虚拟的ICollection< B> GET_PROP()
{
返回_prop;
}

公共虚拟无效set_Prop(ICollection的< B>价值)
{
_prop =价值;
}



因此​​,虚拟关键字可以覆盖子类酒店仅正如你所上述get / set方法:

 公众覆盖的ICollection< b>道具
{
{返回NULL; }
组{}
}


I have used and learned only virtual methods of the base class without any knowledge of virtual properties used as

class A
{
   public virtual ICollection<B> prop{get;set;}
}

Could someone tell me what that means ?

解决方案

public virtual ICollection<B> Prop { get; set; }

Translates almost directly to:

private ICollection<B> _Prop;

public virtual ICollection<B> get_Prop()
{
    return _Prop;
}

public virtual void set_Prop(ICollection<B> value)
{
    _Prop = value;
}

Thus, the virtual keyword allows you to override the property in sub-classes just as you would the above get/set methods:

public override ICollection<B> Prop
{
    get { return null; }
    set { }
}

这篇关于虚拟财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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