Array property syntax in C#

后端 未结 6 623
旧巷少年郎
旧巷少年郎 2020-12-18 23:27

I have a a class that has an integer array property and I am trying to figure out the right syntax for it. The integer array gets instantiated in the class constructor.

6条回答
  •  离开以前
    2020-12-19 00:02

    It is called Auto-Implemented Properties . So if you have syntax like

    public int[] MyNumbers { get; set; }
    

    C# compiler will automatically create for you backing field. This feature was introduced in C# 3.0, and before that you always had to implement property with backing field.

    You can read more at: New C# "Orcas" Language Features: Automatic Properties, Object Initializers, and Collection Initializers

提交回复
热议问题