收藏 分享(赏)

C#数组-补充1.ppt

上传人:j35w19 文档编号:8114519 上传时间:2019-06-09 格式:PPT 页数:11 大小:280.50KB
下载 相关 举报
C#数组-补充1.ppt_第1页
第1页 / 共11页
C#数组-补充1.ppt_第2页
第2页 / 共11页
C#数组-补充1.ppt_第3页
第3页 / 共11页
C#数组-补充1.ppt_第4页
第4页 / 共11页
C#数组-补充1.ppt_第5页
第5页 / 共11页
点击查看更多>>
资源描述

1、,一维数组eg:三个double元素的数组 double dd =new double3;/初始值为 0 double dd = new double3 1.2, 2, 3 ; double dd = 1.2, 2, 3 ; /不推荐若赋值,必须完整一致,多维数组:/ Single-dimensional arrayint numbers = new int5;/ Multidimensional array在方括号内加上逗号string, names = new string5, 4;/ Array-of-arrays (jagged array)交错数组byte scores = new

2、byte5 ;,ArrayList类:可变长度数组 using System.Collections; 属性 .Count, .Capacity, 方法 .Add(), .GetType(), ArrayList可存放任何类型的数据(System.Object) ArrayList 接受 null引用(在 Visual Basic 中为 Nothing) 作为有效值并且允许重复的元素,一维数组演示,static void Main(string args) double dd =new double3 1.2, 2, 3 ;/个数一致Console.WriteLine(“total eleme

3、nts:“+ dd.Length);foreach(double d in dd)Console.WriteLine(d);for(int i=0;idd.Length;i+)Console.WriteLine(ddi); ,二维数组演示,static void Main(string args)double, dd = new double2, 3 1, 2, 3 , 4, 5, 6 ;Console.WriteLine(“total elements:“+ dd.Length);foreach(double d in dd)Console.WriteLine(d);for (int i =

4、 0; i dd.GetLength(0); i+)for (int j = 0; j dd.GetLength(1); j+)Console.Write(ddi, j+“,“);Console.WriteLine(); ,Jagged Array交错数组,static void Main(string args)int scores = new int5 ; for (int i = 0; i scores.Length; i+)scoresi = new inti + 3; scoresi1 = i + 3;for (int i = 0; i scores.Length; i+)Conso

5、le.WriteLine(“Length:row 0 is 1“, i, scoresi.Length);foreach (int row in scores)foreach (int e in row)Console.Write(e + “,“);Console.WriteLine();,多维数组与交错数组比较,int, dd = new int2, 3; foreach(int e in dd)Console.Write(e);int scores = new int5 ; foreach (int row in scores)foreach (int e in row)Console.W

6、rite(e);,ArrayList演示,static void Main(string args)ArrayList myAL = new ArrayList();myAL.Add(“Welcome “);myAL.Add(null);myAL.Add(“you “);myAL.Add(2011);Console.WriteLine(myAL.Count);for (int i = 0; i myAL.Count; i+)Console.WriteLine(myALi);Console.WriteLine(myAL3.GetType();,表达式,定义: 由常量、变量、函数等通过运算符连接而成的一个有意义是算式,代表一个具有特定类型的具体值或对象。一般形式:运算符 ,运算符,数学运算符 + (+) 、 - (-) * 、/ % 赋值运算符 简单赋值:= 复合赋值:+= -= *= /= %= 位运算符: & | 逻辑运算符:! | & 关系运算符:= != = 条件运算符:? : ,运算符,运算符优先级与结合性 优先级:不同运算符参与运算是的先后顺序 结合性:优先级相同的运算按结合方向确定运算次序 右结合(从右到左):一元运算符、条件运算符、赋值运算符 左结合(从左到右):其他大部分运算符,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报