Omitted setter vs private setter?

前端 未结 5 699
情书的邮戳
情书的邮戳 2020-12-15 02:53

What is the difference between a property with a omitted setter and a property with a private setter?

public string Foo { get; private set; }
5条回答
  •  我在风中等你
    2020-12-15 03:38

    The private setter is - well - a private set method you can use from inside your class only.

    The omitted setter makes the property readonly. So you can only set the value of this property in your constructor(s) or via a static initialization.

提交回复
热议问题