C#的三种声明

一:枚举变量

 public enum Gender
    {
        男,
        女
    }

 枚举变量可以更好的减少由数字转置错误引起的错误,以后改值更加容易,代码更加容易读,确保向前兼容性,数据的一致性。

 

二:结构体

    public struct People
    {
        public string _name;
        public int _age;
        public MyName _gender;
    }

 

三:数组

            int[] nums1 = new int[] { 2, 3, 4 };
            int[] nums2 = new int[25];
            int[] nums3 = new int[3] { 1,2,3};
            int[] nums = { 1, 2, 3, 4, 5 };

猜你喜欢

转载自blog.csdn.net/hlzdbk/article/details/117126051
今日推荐