首页 > 代码库 > c#笔记(六)——数组

c#笔记(六)——数组

数组定义,数组初始化:动态初始化,静态初始化
int[ ] array=new int[6];   new 是运算符;数值类型初始值为0,bool类型是false,字符串初始值null.
动态初始化:数据类型[] 数组名=new 数据类型[数组长度]{元素1,元素2};
//数组的动态初始化
            int[] array = new int[6] { 1, 2, 3, 4, 5, 6 };
            int[] arr1 = new int[] { 1, 2, 3, 4, 5, 6 };
            //数组的静态初始化,只能写在一行
            //int[] arr2 = { 7, 8, 9, 10, 11, 12 };
            //int i = 0;
            //Console.WriteLine(arr1[i]);
            //i++;
            //Console.WriteLine(arr1[i]);
            //Console.WriteLine(arr1.Length);
            for (int i = 0; i < arr1.Length; i++)
            {
                Console.WriteLine(arr1[i]);
            }
  Console.ReadKey();

c#笔记(六)——数组