C# 对象初始化器 和数组初始化语法

    public class test
    {
        //属性
        public unicode_gb[] m_unicode_gb = new unicode_gb[10];
        public A[] m_A = new A[10];
        public class A
        {
            public int unicode;
            public int gb;
        }
        public struct unicode_gb
        {
            //unsigned short无符号短整型0~65535
            public int unicode;
            public int gb;
        }

        public void func()
        {
            //定义字符串数组
            string[] strDoorStatus = { "invalid", "sleep", "Normally open", "Normally close" };
            string[] arrayB = new string[3] { "shirdrn", "Hamtty", "Saxery" };
            string[] arrayC = new string[3];
            arrayC[0] = "Shirdrn";
            arrayC[1] = "Hamtty";
            arrayC[2] = "Saxery";

            //对象初始化器
            //T_Sys_UnitTest data = new T_Sys_UnitTest
            //{
            //    Id = Guid.NewGuid().ToString(),
            //    UserId = Guid.NewGuid().ToString(),
            //    Age = 10,
            //    UserName = Guid.NewGuid().ToString()
            //};

            m_unicode_gb = new unicode_gb[]
            {
                 new unicode_gb{
                    unicode =0
                }
            };

            var m_A = new A[] {

                new A{
                    unicode =0
                }

            };

        }
    }

 

posted @ 2020-03-09 17:24  enych  阅读(1370)  评论(0编辑  收藏  举报