本次课我主要学习了二维数组和集合的部分内容。

在二维数组的部分中,我主要学习了二维数组的定义方法:int [,] array=new int [4,2];做了一个小练习:用二维数组打印自己的姓氏。

string[,] a = new string[11, 9]
{
{" "," "," "," ","■"," "," "," "," "},
{" "," "," "," ","■"," "," "," "," "},
{" ","■","■","■","■","■","■","■"," "},
{" "," "," ","■","■","■"," "," "," "},
{" ","■","■"," ","■"," ","■","■"," "},
{" "," ","■","■","■","■","■"," "," "},
{" "," "," "," "," ","■"," "," "," "},
{"■","■","■","■","■","■","■","■","■"},
{" "," "," "," ","■"," "," "," "," "},
{" "," "," ","■","■"," "," "," "," "},
{" "," "," "," ","■"," "," "," "," "},
};
for (int i = 0; i < 11; i++)
{
for (int j = 0; j < 9; j++)
{
Console.Write(a[i, j]);
}
Console.WriteLine();
}
Console.ReadLine();

然后,我学习了一个split() 分离

例:

一次性接收姓名、年龄、工作单位
Console.Write("请输入您的姓名、年龄、工作单位(**-**-**):");
string quan = Console.ReadLine();
string[] array = quan.Split('-');
for (int i = 0; i < array.Length; i++)
{
Console.WriteLine(array[i]);
}
Console.ReadLine();

学习完二维数组的内容,我开始学习了集合的部分内容。

ArrayList al = new ArrayList();//初始化
al.Add(5);
al.Add(3);
al.Add(6);
al.Add(4);
al.Add(1);
al.Add(2);
al.Add("2");
al.Add("hello");
al.Add(true);
al[3] = "你好";
al.Clear(); 移除所有元素
ArrayList al1 = new ArrayList();

al1 = (ArrayList)al.Clone();//克隆
//判断是否包含
Console.WriteLine(al1.Contains("2"));
//获取第一次出现该元素的索引号
Console.WriteLine(al1.IndexOf(11));
//获取最后一次出现该元素的索引号
Console.WriteLine(al1.LastIndexOf(2));
//插入某个索引位置某个元素
al.Insert(2,"Hello");

//移除某个第一次出现的元素
al.Remove("hello");
//移除某个索引位置的元素
al.RemoveAt(3);

al.Sort();//排序 ,升序
al.Reverse();//翻转整个集合
Console.WriteLine(al[2]);
Console.WriteLine(al.Count);
Console.ReadLine();

在学习了集合的基本知识之后,我做了一个综合性的题目来对我所学习的内容加以巩固。

例:输入班级人数,输入每个人的姓名、语数英成绩进入集合;求语文的总分,数学的平均分,英语的最高分的人的姓名及所有科目的分数(冒泡排序)

0     姓名  4   8  12
    1 语文成绩5   9  13
    2 数学成绩6 10  14
    3 英语成绩7 11  15

Console.Write("请输入班级人数:");
int n = int.Parse(Console.ReadLine());
double yu = ;
double shu = ;
ArrayList al = new ArrayList();
for (int i = ; i < n; i++)
{
Console.Write("请输入第{0}个人的姓名:",i+);
al.Add(Console.ReadLine());
Console.Write("请输入第{0}个人的语文成绩:",i+);
al.Add(double.Parse(Console.ReadLine()));
yu += double.Parse(al[al.Count - ].ToString());
Console.Write("请输入第{0}个人的数学成绩:", i + );
al.Add(double.Parse(Console.ReadLine()));
shu += double.Parse(al[al.Count - ].ToString());
Console.Write("请输入第{0}个人的英语成绩:", i + );
al.Add(double.Parse(Console.ReadLine()));
}
Console.WriteLine("所有信息输入完毕,请按回车键继续!");
Console.ReadLine();
Console.WriteLine("语文的总分是:"+yu);
Console.WriteLine("数学的平均分是:"+(shu/n)); for (int i = ; i < *n-; i+=)
{
for (int j = i; j < * n - ; j += )
{
if (double.Parse(al[i].ToString()) < double.Parse(al[j + ].ToString()))
{
//换姓名
object zhong = al[i - ];
al[i - ] = al[j + ];
al[j + ] = zhong;
//换语文
zhong = al[i - ];
al[i - ] = al[j + ];
al[j + ] = zhong;
//换数学
zhong = al[i - ];
al[i - ] = al[j + ];
al[j + ] = zhong;
//换英语
zhong = al[i];
al[i] = al[j + ];
al[j + ] = zhong;
}
}
}
Console.WriteLine("英语最高分的学生是{0},英语分数是{1},语文分数是{2},数学分数{3}",al[],al[],al[],al[]);
Console.ReadLine();

C# 二维数组和集合的更多相关文章

  1. C#(二维数组/集合)

    一.二维数组int [,] array = new int[5,3];//有五个一维数组,每一个一维数组有3个元素 /打印出来一个“王”这个字string[,] wang = new string[, ...

  2. PHP 如何获取二维数组中某个key的集合(高性能查找)

    分享下PHP 获取二维数组中某个key的集合的方法. 具体是这样的,如下一个二维数组,是从库中读取出来的. 代码: $user = array( 0 => array( 'id' => 1 ...

  3. PHP 获取二维数组中某个key的集合

    本文为代码分享,也是在工作中看到一些“大牛”的代码,做做分享. 具体是这样的,如下一个二维数组,是从库中读取出来的. 代码清单: $user = array( 0 => array( 'id'  ...

  4. 二维数组,锯齿数组和集合 C# 一维数组、二维数组(矩形数组)、交错数组(锯齿数组)的使用 C# 数组、多维数组(矩形数组)、锯齿数组(交叉数组)

    二维数组,锯齿数组和集合 一.二维数组 二维数组:一维数组----豆角二维数组----表格 定义:1.一维数组:数据类型[] 数组变量名 = new 数据类型[数组长度];数据类型[] 数组变量名 = ...

  5. PHP使用array_filter查找二维数组中符合字段和字段值的数据集合

    1.方法: /** * 获取符合字段和字段值的数组集合 * @param array $data 待过滤数组 * @param string $field 要查找的字段 * @param $value ...

  6. php获取二维数组中某一列的值集合

    $result //二维数组$uid_list = array_column($result, 'uid');

  7. ***php解析JSON二维数组字符串(json_decode函数第二个参数True和False的区别)

    客户端的请求体中的数据:[{"msg_id": 1, "msg_status": "HAS_READ" }, { "msg_id& ...

  8. Android 在资源文件(res/strings.xml)定义一维数组,间接定义二维数组

    经常我们会在资源文件(res/strings.xml)定义字符串,一维数组,那定义二维数组?直接定义二维数组没找到,可以间接定义. 其实很简单,看过用过一次就可以记住了,一维数组估计大家经常用到,但是 ...

  9. 数组(Array),二维数组,三维数组

    数组(Array):相同类型数据的集合就叫做数组. (一)定义数组的方法: A) type[] 变量名 = new type[数组中元素的个数] 例如: int[] a = new int[10] ; ...

随机推荐

  1. #数论-模运算#POJ 1150、1284、2115

    1.POJ 1150 The Last Non-zero Digit #质因数分解+模运算分治# 先贴两份题解: http://www.hankcs.com/program/algorithm/poj ...

  2. 洛谷-均分纸牌-NOIP2002提高组复赛

    题目描述 Description 有 N 堆纸牌,编号分别为 1,2,…, N.每堆上有若干张,但纸牌总数必为 N 的倍数.可以在任一堆上取若于张纸牌,然后移动. 移牌规则为:在编号为 1 堆上取的纸 ...

  3. 设置ios中imageView图片自适应,

    UIIimageView  *imageView = [UIImageView alloc]init]; [imageView setContentScaleFactor:[[UIScreen mai ...

  4. tcp协议栈

    TCP/IP是互联网的核心协议,也是大多数网络应用的核心协议.就前面一段时间面试中问到的TCP/IP问题,这里给出一个简单的小结.   TCP由RFC793.RFC1122.RFC1323.RFC20 ...

  5. Python入门学习

    1.访问www.python.org/download下载并安装Python3版本 2.命令行输入python启动交互式命令shell,>>>代表当前行用户的输入 3.基本算数运算: ...

  6. unsupported major.minor version 52.0,错误

    Make sure that all the classes needed by the application have been compiled with a compatible java v ...

  7. JAVA中String(字符串)课堂总结

    一:Java编译器中关于字符串自动优化 例子一: 源代码: public class StringPool { public static void main(String args[]) { Str ...

  8. 分布式版本控制系统Git-----5.Git 的push命令总结

    git push git push命令用于将本地分支的更新,推送到远程主机.它的格式与git pull命令相仿. git push <远程主机名> <本地分支名>:<远程 ...

  9. jquery操作ajax返回的页面元素

    这两天工作不忙,正好从朋友那里拿到一个某个应用的开发文档,相关数据放在了mongodb里,自己电脑可以本地开启服务器然后通过给的借口来获取数据.由于这是一个比较大比较全的一个完整项目,也没有那么多经历 ...

  10. crontab格式使用方式

    第1列分钟1-59第2列小时1-23(0表示子夜)第3列日1-31第4列月1-12第5列星期0-6(0表示星期天)第6列要运行的命令 下面是crontab的格式:分 时 日 月 星期 要运行的命令 这 ...