Array property syntax in C#

后端 未结 6 624
旧巷少年郎
旧巷少年郎 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:01

     class DemoClass
        {
            private int[] myNumbers;
            public int[] MyNumbers
            {
                get { return myNumbers; }
                set { myNumbers = value; }
            }
    
            public DemoClass(int[] elements)
            {
                myNumbers = elements;
                // Here, the array should get instantiated using the elements.
            }
        }
    

提交回复
热议问题