C#部分---二维数组、split分割;

本文介绍了C#中的二维数组定义方式,并展示了如何使用split方法以特定字符进行字符串分割。通过示例代码,解释了如何读取用户输入,对数据进行处理,包括获取数组中的特定值和对数组进行筛选操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

二维数组
定义方式:

int[,] array = new int[3, 4]{
{1,2,3,4},
{3,4,5,6},
{5,6,7,8}
};                  3表示,有三个一维数组
                     4表示,每一个一维数组中有4个元素。

split() 以***进行分割
分割开的内容需要放置在string类型的数组中,不需要给数组定义长度

string s = Console.ReadLine() ;
string[] array = s.Split('-');
foreach(string aa in array)
{
Console.WriteLine(aa);
}

输入班级人数,
//输入每个人的语数英成绩
//求语文两个最高分,数学两个最低分,英语平均分

 

 //Console.WriteLine("请输入班级人数:");
                //int n = int.Parse(Console.ReadLine());
                //double[,] chengji = new double[n, 3];
                //for (int i = 0; i < n; i++)
                //{
                //    Console.Write("请输入第{0}个学生语文的成绩:", (i + 1));
                //    chengji[i, 0] = double.Parse(Console.ReadLine());
                //    Console.Write("请输入第{0}个学生数学的成绩:", (i + 1));
                //    chengji[i, 1] = double.Parse(Console.ReadLine());
                //    Console.Write("请输入第{0}个学生英语的成绩:", (i + 1));
                //    chengji[i, 2] = double.Parse(Console.ReadLine());
                //}
                //for (int j = 0; j < n - 1; j++)
                //{
                //    for (int k = j + 1; k < n; k++)
                //    {
                //        if (chengji[j, 0] < chengji[k, 0])
                //        {
                //            double zhong = chengji[j, 0];
                //            chengji[j, 0] = chengji[k, 0];
                //            chengji[k, 0] = zhong;
                //            double zhong1 = chengji[j, 1];
                //            chengji[j, 1] = chengji[k, 1];
                //            chengji[k, 1] = zhong1;
                //            double zhong2 = chengji[j, 2];
                //            chengji[j, 2] = chengji[k, 2];
                //            chengji[k, 2] = zhong2;
                //        }
                //    }
                //}
                //Console.WriteLine("语文成绩最高的两位分别是{0},{1}", chengji[0, 0], chengji[1, 0]);
                //for (int w = 0; w < n - 1; w++)
                //{
                //    for (int y = w + 1; y < n; y++)
                //    {
                //        if (chengji[w, 1] < chengji[y, 1])
                //        {
                //            double zhong = chengji[w, 0];
                //            chengji[w, 0] = chengji[y, 0];
                //            chengji[y, 0] = zhong;
                //            double zhong1 = chengji[w, 1];
                //            chengji[w, 1] = chengji[y, 1];
                //            chengji[y, 1] = zhong1;
                //            double zhong2 = chengji[w, 2];
                //            chengji[w, 2] = chengji[y, 2];
                //            chengji[y, 2] = zhong2;
                //        }
                //    }
                //}
                //Console.WriteLine("数学成绩最低的两位分别是{0},{1}", chengji[n - 1, 1], chengji[n - 2, 1]);
                //double sum = 0;
                //for (int k = 0; k < n; k++)
                //{
                //    sum = sum + chengji[k, 2];
                //}
                //Console.WriteLine("英语平均分是:{0}", (sum / n));

 

//随意输入20个数字,放入数组,
////将数组中偶数索引上的值去除,放入另一个数组,然后打印出来

//Random ran=new Random();
                //int[]aa=new int[20];
                //int[]bb=new int[10];
                
                //for (int i = 0; i < 20;i++)
                //{
                //    aa[i] = ran.Next();
                //}
                //foreach(int cc in aa)
                //{
                //    Console.WriteLine(cc);
                //}
                //Console.Write("请按回车键继续。");
                //Console.ReadLine();
                //for (int j = 0; j < 10;j++ )
                //{
                //    bb[j]=aa[j*2+1];
                //}
                //foreach(int dd in bb)
                //{
                //    Console.WriteLine(dd);
                //}

 

转载于:https://www.cnblogs.com/xingyue1988/p/5965069.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值