数组(for 循环+等量代换)

     //数组!

            //  int[] shuzu = new int[6] { 1, 2, 3, 4, 5, 6 };//索引是从0开始。[]内表示数组包含的数值 个数!             //  int i = shuzu[2];//此处2 表示数组shuzu的索引!这是引用数组的格式!

            /*    int[] shuzu = new int[6];

                 shuzu[0] = 1;

                 shuzu[1] = 2;

                 shuzu[2] = 3;  //当 索引 没赋值时,提取到的是0

                 int i=shuzu.[3];

                 Console.Write(i);     //显示值是   0

                 Console.ReadLine();    */

/*    求平均分  和  最大最小分值!

            Console.Write ("人数");

            int n=int.Parse (Console.ReadLine());

            int[] i = new int[n];       //创建数组i,包含n个数值!

            int zongfen = 0;

            double b = 0;

            for (int a = 0; a < n; a++)

            {

                 Console.Write("第"+(a+1)+"人分数");

                i[a] = int.Parse (Console.ReadLine());      //赋值。数组i里索引为a的值

                zongfen+= i[a];                   //总和的表示方式

            }

            b = zongfen / n;

            Console.WriteLine("平均分"+b+"总分"+zongfen );

            int max = i[0]; int min = i[0];    //赋值数组里的一个数,然后用if 判断大小,然后分大小赋值!

            for (int c = 0; c < n; c++)

            {

                if (i[c] >= max)               //比较大小!

                {

                  max = i[c];

                }

                if (i[c] <= min)               //比较大小!

                {

                  min=i[c];

                }

            }

            Console.Write("max" + max + "min" + min);

            Console.ReadLine();

  /*   Console.Write("人数:");

            int r = int.Parse(Console.ReadLine ());

            int[]ren=new int[r];

            for (int a = 0; a < r; a++)

            {

                Console.Write("第"+(a+1)+"个人分数");

               ren[a]=int.Parse (Console.ReadLine ());

            }

            int d = 0;

            for (int b = 0; b < r; b++)            //升(降)序排列(冒泡排列法)

            {

                for (int c = b; c < r-1; c++)

                {   d = ren[b];                        //中间值赋值要先于if判断,就好比 if (ren[b] < ren[c + 1])

                    if (ren[b] > ren[c + 1])    //把有用的留下,没用的删除掉.关键在if判断大小和等量代换

                     {               

                        ren[b] = ren[c + 1];         

                        ren[c + 1] = d;

                     }

                }

            }

           // foreach (int e in ren)         //表示创建新变量e从数组ren中按顺序取值。

           // Console.Write(e);

            for (int e = 0; e < r;e++)         //同上。

            { Console.Write(ren[e]);}

             Console.ReadLine();     */

           //二维数组

       /*

     int[,] ss = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };

        //[]内2代表数组个数,3代表数组内数值数量!索引都是从  0   开始!

       Console.Write (ss[1,2]);     //此时输出  是  6

        ss[1,0]=7;    //赋值   //此时原数组例的4 ,变成了7.      

           Console.Write(ss[1, 0]);

            Console.ReadLine ();           */

 /*    //n个人的语数外分数

            Console.WriteLine("人数:");

            int n = int.Parse(Console.ReadLine ());

          //  Console.WriteLine("课程数:");

          //  int m = int.Parse(Console.ReadLine());

                        int[,]fen=new int[n,3];

            for (int a = 0; a < n; a++)

            {

                    Console.WriteLine("请输入第"+(a+1)+"人的语文分数:");

                    fen[a, 0] = int.Parse(Console.ReadLine());

                     Console.WriteLine("请输入第"+(a+1)+"人的数学分数:");

                    fen[a, 1] = int.Parse(Console.ReadLine());

                 Console.WriteLine("请输入第"+(a+1)+"人的外语分数:");

                    fen[a, 2] = int.Parse(Console.ReadLine());

            }

           /* foreach (int b in fen)

           // { Console.WriteLine(b); } 

           //可以打印所有集合中的元素。按照索引顺序[0,0],[0,1],[0,2]……[n-1,0],[n-1,1],[n-1,2]   */

            double  c = 0, d = 0, e = 0;           //一次创建多个变量!要用,分隔开!

            for (int b = 0; b < 2; b++)

            {

                c += fen[b, 0];                 d += fen[b, 1];                 e += fen[b, 2];

             }

            Console.WriteLine("语文平均分" + c / 2 + "数学平均分" + d / 2 + "外语平均分" + e / 2);

                Console.ReadLine();      */

       /*   //随机生成4位验证码

                string s = "abcdefghijklmnopqrstuvwxyz0123456789";

                Random a= new Random();

                string c="";

                for (int b = 0; b < 4; b++)

                {

                     int n = a.Next(s.Length);

                     c = s.Substring(n, 1)+c;

                }

                Console.WriteLine(c);

                Console.ReadLine();               */

     /*   回顾   string s = Console.ReadLine();

            int i = s.Length;

            s = s.Trim();

            s = s.TrimStart();

            s = s.TrimEnd();

            s = s.ToUpper();

            s = s.ToLower();

            s = s.Substring(0,1);

            s = s.Replace("w","e");

            Console.WriteLine(s);

            Console.ReadLine();   */

原文地址:https://www.cnblogs.com/huaze/p/4037576.html