繁体   English   中英

设定属性中的C#Lambda

[英]C# Lambda in set property

通过阅读C#示例,我发现set属性中使用了lambda:

 private bool _inProgress;
 public bool InProgress
        {
            get {
                return _inProgress;
            }
            set { Set(() => InProgress, ref _inProgress, value); }
        }

但是它对我不起作用,我明白了

the name "Set" does not exist in current context

错误。

我发现这种语法{Set(() => InProgress, value);}等于{return InProgress = value;}正确吗? 但是我仍然得到the name "Set" does not exist in current context错误the name "Set" does not exist in current context

查看在哪里找到它的类,您会发现它是从另一个类继承的,因此Set可能是超类的成员,要使其正常工作,您的类也必须继承该类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM