第十一讲:字符串
1、string是一种特殊的引用类型,使用起来好像值类型
例:class Program
    {
        static void Main(string[] args)
        {
            string s = "123";
            string k = s;
            k = "456";
            Console.WriteLine(s);
        }
    }
结果:123
2、string中部分函数的意思trim除去空格 ToUpper把字母转换为大写 Split分割
例:class Program
    {
        static void Main(string[] args)
        {
            string str = "    123456";
            Console.WriteLine(str);
            Console.WriteLine(str.Trim());
        }
    }
结果:   123456
     123456
第十二讲:数组
1、Array:在.NET中所有的数组都是继承在Array下的,是引用类型,不能够直接定义。实例化的时候不可以用new关键字。属于抽象类,可以被子类实例化。
例:static void Main(string[] args)
        {
            Array arr = Array.CreateInstance(typeof(int), 10);
            for (int i = 0; i < 10; i++)
            {
                arr.SetValue(i * 2, i);
            }
            foreach (int i in arr)
            {
                Console.WriteLine(i);
            }
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(arr.GetValue(i));
            }
        }
2、一维数组:int[] arrint=new int[10]
(1)Array方法有Sort排序
例:class Program
    {
        static void Main(string[] args)
        {
            int[] arri = new int[] { 2, 35, 1, 3, 53, 216, 1 };
            Array.Sort(arri);
            int len=arri.Length;
            for (int i = 0; i < len; i++)
            {
                Console.WriteLine(arri[i]);
            }
        }
    }
结果:1
      1
      2
      3
      35
      53
      216

(2)Array方法中的Reverse方法表示反转
例:static void Main(string[] args)
        {
            int[] arri = new int[] { 2, 35, 1, 3, 53, 216, 1 };
            Array.Sort(arri);
            Array.Reverse(arri);
            int len=arri.Length;
            for (int i = 0; i < len; i++)
            {
                Console.WriteLine(arri[i]);
            }
        }
结果:216
      53
      35
      3
      2
      1
      1
3、二维数组定义:int[,] arri=new int[i,j];
int[,] arri = new int[,] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 } };
例:int[,] arri = new int[,] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 } };
            for (int r = 0; r < 2; r++)
            {
                for (int c = 0; c < 4; c++)
                {
                    Console.WriteLine(arri[r,c]);
                }
            }
4、交错数组:数组中的数组 定义:int[][] arri=new int[2][];不允许有第二个方括号的值的不允许有列
例: int[][] arri = new int[3][];
            arri[0] = new int[] { 1, 2 };
            arri[1] = new int[] { 3};
            arri[2]=new int[]{4,5,6};
            int rlen = arri.Length;
            for (int i = 0; i < rlen; i++)
            {
                int clen = arri[i].Length;
                for (int j = 0; j < clen; j++)
                {
                    Console.WriteLine(arri[i][j]);
                }
            }
            //foreach (int[] i in arri)
            //{
            //    foreach (int j in i)
            //    {
            //        Console.WriteLine(j);
            //    }
            //}
foreach和for循环的结果一样都为:
1
2
3
4
5
6
也可以打印单个元素:Console.WriteLine(arri[2][2]);打印结果为6.
5、用数组写学生管理系统
例:namespace Chapter12Demo2
{
    class Program
    {
        static void Main(string[] args)
        {
            string [,] arri=new string[3,3];
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (j == 0)
                    {
                        Console.WriteLine("请输入学生的姓名:");
                       arri[i,j] = Console.ReadLine();
                    }
                    else if (j == 1)
                    {
                        Console.WriteLine("请输入年龄:");
                        arri[i,j] = Console.ReadLine();
                    }
                    else
                    {
                        Console.WriteLine("请输入性别:");
                        arri[i,j] = Console.ReadLine();
                    }
                }

 }
           
            for (int i = 0; i <3; i++)
            {
                for (int j = 0; j <3; j++)
                {
                    Console.Write(arri[i,j]);
                }
                Console.WriteLine();
            }
        }
    }
}