zoukankan      html  css  js  c++  java
  • C#基础(数组)

    数组:一次性定义固定长度的一组数据;

    数据类型[] 数组名 =new 数据类型[(个数)]

               //输入n个人的分数,按分数从高到低排序

              /* Console.WriteLine("输入人数:");

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

                int[] arr = new int[n];

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

                {

                    Console.Write("第"+(i+1)+"个人的成绩为:");

                    arr[i]=int.Parse (Console .ReadLine ());

                }

                for (int j = 0; j < arr.Length-1; j++)

                {

                    for (int i = j + 1; i < arr.Length; i++)

                    {

                        if (arr[j] < arr[i])

                        {

                            int zhong = arr[i];

                            arr[i] = arr[j];

                            arr[j] = zhong;

                        }

                    }

                }

                for (int i = 0; i <arr. Length; i++)

                {

                    Console.Write(arr[i]);  

                }

                */

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

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

               string []arr=new string [n];

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

                {

                    Console.Write("第"+(i+1)+"个人的手机号为:");

                    arr[i]= Console .ReadLine ();

                }

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

                {

                    Console.Write(arr[i]);

                    Thread .Sleep(100);

                    Console.Clear();

                }

                Random r = new Random();

                int index = r.Next(0,n);

                Console.Write(arr[index ]);*/

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

                for (int i = 0; i < 6; i++)

                {

                    Random r = new Random();

                    arr[i] = r.Next(1,34);

                    for (int j = 0; j < i; j++)

                    {

                        if(arr[j]==arr[i])

                        {

                            i--;

                            break;

                        }

                    }

                }

                foreach (var a in arr)

                {

                    Console.Write(a+"   ");

                }

                Random b = new Random();

                int c = b.Next(1, 17);

                Console.WriteLine(c);

    二维数组:多个一维数组就是二维数组;

    Int [,]arr=new int[,]

  • 相关阅读:
    postman中 form-data、x-www-form-urlencoded、raw、binary的区别
    常见的http response
    ==容易错误的例子
    点击panel滚动条滚动到底部
    fabric实现文本聚焦、可编辑
    JSON.parse()和JSON.stringify()的使用
    centos7安装mysql
    阿里云第一次访问tomcat非常慢的解决办法
    java中的语法糖
    jvm | 基于栈的解释器执行过程
  • 原文地址:https://www.cnblogs.com/wallan/p/5343867.html
Copyright © 2011-2022 走看看