Is there a way to make readonly (not just private) automatic properties?

前端 未结 6 593
日久生厌
日久生厌 2020-12-31 13:02

Automatic properties let me replace this code:

private MyType myProperty;
public MyType MyProperty
{
    get { return myPropertyField; }
}

6条回答
  •  清酒与你
    2020-12-31 13:52

    No, there's no way you can do it. In fact, I don't see why would you want to get a value of a property which has not been set previously. For obvious reasons, you cannot set the value if there's neither set accessor, nor backing field.

提交回复
热议问题