C#数组_160921

double[] y = new double[3];声明部分跟C不同了。。。

y.length();可以直接查看数组长度

char[] b=new char[]{'a', 'b', 'c'};初始化

foreach循环使可以不依赖索引而读取每个数组元素,

=============一个栗子============================

            int[] num = { 3, 34, 42, 2, 11, 19, 30, 55, 20 };

            //int x;
            foreach (int x1 in num)
            {
                if (x1 % 2 == 0)
                    Console.WriteLine(x1);
            }

二维数组

int[ ,] arr=new int[2,3]//两个一维数组,每个数组包含3个变量,总共六个元素

访问arr[1,0]

======================一个栗子=========================

            int[,] score = new int[4, 2] { { 89, 86 }, { 69, 40 }, { 64, 92 }, { 82, 100 } };
            Console.WriteLine("the score are:");
            for (int i = 0; i < score.GetLongLength(0); i++)
            {
                Console.WriteLine("语文:{0},数学{1}",score[i,0],score[i,1]);          
            }

======================================================

int.Parse(Console.RaedLine());//把输入转换为int型

            string[] name = new string[5];
            int[] score = new int[5];
            for (int i = 0; i < name.Length; i++)
            {
    
                Console.Write("please input the name:  ");
                name[i] = Console.ReadLine();
                Console.Write("please input the score:  ");
                score[i] = int.Parse(Console.ReadLine());

            }

            int sum = 0, avg;
            for (int i = 0; i < name.Length; i++)
            {
                sum = sum + score[i];

            }
            avg = sum / 5;
            Console.Write(avg);



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值