• 数组


    一维数组(相同数据类型)
    第一种定义方式

                int[] shuzu = new int[5];
                for (int i = 0; i < 5; i++)
                {
                    shuzu[i] = i + 1;
                }
                //索引从0开始
                //赋值
                shuzu[0] = 1;
                shuzu[1] = 2;
                shuzu[2] = 3;
                shuzu[3] = 4;
                shuzu[4] = 5;
                Console.Write(shuzu[2]);

    第二种定义方式

    从控制台输入10个人的年龄放入数组
    将十个人的年龄求总和

                int[] age = new int[10];
                int a = 0;
                for (int i = 0; i < 10; i++)
                {
                    Console.Write("请输入第" + (i + 1) + "个人的年龄:");
                    age[i] = int.Parse(Console.ReadLine());
                    a += age[i];
                }
                Console.WriteLine(a);

    二维数组

                int[,] shuzu = new int[3, 4];
                int[,] shuzu = new int[,]{
                {1,2,3,4},
                {5,6,7,8},
                {6,7,8,9}
                };

    输入班级人数,将每个人的
    语文,数学,英语成绩输入二维数组

                Console.Write("请输入班级人数:");
                int a = int.Parse(Console.ReadLine());
                double[,] c = new double[a, 3];
                for (int i = 0; i < a; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        if (j == 0)
                        {
                            Console.Write("请输入第" + (i + 1) + "个人的语文成绩:");
                        }
                        if (j == 1)
                        {
                            Console.Write("请输入第" + (i + 1) + "个人的数学成绩:");
                        }
                        if (j == 2)
                        {
                            Console.Write("请输入第" + (i + 1) + "个人的英语成绩:");
                        }
                        c[i, j] = double.Parse(Console.ReadLine());
                    }
                }

    写出汉字”企“

                string[,] a = new string[,]
               { 
               {"  ","  ","  ","","  ","  ","  "},
                {"  ","  ","","  ","","  ","  "},
                {"  ","","  ","  ","  ","","  "},
                {"","  ","  ","","  ","  ",""},
                {"  ","  ","  ","","  ","  ","  "},
                {"  ","","  ","","","","  "},
                {"  ","","  ","","  ","  ","  "},
                {"","","","","","",""}
               };
    
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 7; j++)
                    {
                        Console.Write(a[i, j]);
                    }
                    Console.WriteLine();
                }
  • 相关阅读:
    [转]NopCommerce MVC 插件机制分析
    压力测试的轻量级具体做法[转载]
    导入IP安全策略图解
    Grunt使用心得
    解决yarn管理资源管理,其他应用起不来
    Spark 读取mysql中的数据
    Spark 配置连接hive 元数据库(mysql)
    Linux安装anaconda和集成PySpark
    python(配置)
    Python 数据爬取(环境变量)
  • 原文地址:https://www.cnblogs.com/zbxiaoxu/p/5269022.html
Copyright © 2020-2023  润新知