Lambda for getter and setter of property

前端 未结 3 1716
孤独总比滥情好
孤独总比滥情好 2020-12-02 16:17

In C# 6.0 I can write:

public int Prop => 777;

But I want to use getter and setter. Is there a way to do something kind of the next?

3条回答
  •  鱼传尺愫
    2020-12-02 16:55

    There is no such syntax, but the older syntax is pretty similar:

        private int propVar;
        public int Prop 
        {
            get { return propVar; }
            set { propVar = value; }
        }
    

    Or

    public int Prop { get; set; }
    

提交回复
热议问题