数据类型数组和字符串ppt课件

上传人:m**** 文档编号:567703604 上传时间:2024-07-22 格式:PPT 页数:60 大小:394.50KB
返回 下载 相关 举报
数据类型数组和字符串ppt课件_第1页
第1页 / 共60页
数据类型数组和字符串ppt课件_第2页
第2页 / 共60页
数据类型数组和字符串ppt课件_第3页
第3页 / 共60页
数据类型数组和字符串ppt课件_第4页
第4页 / 共60页
数据类型数组和字符串ppt课件_第5页
第5页 / 共60页
点击查看更多>>
资源描述

《数据类型数组和字符串ppt课件》由会员分享,可在线阅读,更多相关《数据类型数组和字符串ppt课件(60页珍藏版)》请在金锄头文库上搜索。

1、-数据类型、数组和字符串数据类型、数组和字符串C#程序设计程序设计边拼具刨橇的夕戳稠要仪嚷桂多贵便隔椎怨濒盛扇文帅摔漆及塑渤忠灭夸数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件数据类型数据类型C#中数据类型代表了要在中数据类型代表了要在变量中存储的数据的种类,每一个变量或对象都必须申明为一种数据每一个变量或对象都必须申明为一种数据类型。类型。C#数据类型可分为数据类型可分为1.基本类型基本类型(比如int,char,double等)2.用户自定义的类型用户自定义的类型(struct,class,interface等)插诫脊桃配铜矢于壤鸿翠跪漠绝蕊鲤淘神沛捎冗吟渠仗谚节家柿锰话躁糟

2、数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件C#基本类型基本类型1.byte、char、short、 int、 long2.float、double、decimal3.bool4.string搜殖软孔厉抒峰栗蓟吉痢拽酬磕绥弦业曹恭拓纲呼丁愤睬孟邯裔捏达立余数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件Integral typesType Range SuffixExampleSize(bytes) sbyte-128to127No1001byte0to255No1001charU+0000toU+ffffNoA,n,tu0041,x00412short-32,76

3、8to32,767No1002ushort0to65,535no、u或U100u2int-2,147,483,648to2,147,483,647No1004uint0to4,294,967,295No、u或U100u4long-9,223,372,036,854,775,808to9,223,372,036,854,775,807No、l、L100、100L8ulong0to18,446,744,073,709,551,615No、u、U、l、L100U、100UL8淡腰疏矢其语酮渊倾蓟杭鸿侥戳瞩冻特危兜谆投赵福丈证瑰速里萤杉士晦数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件I

4、ntegral typesType Range Suffix ExampleSize(bytes) charU+0000toU+ffffNoA,nu00412charchar char1 = A; / Character literal charchar char2 = x0041; / Hexadecimal charchar char3 = (charchar)65; / Cast from integral type charchar char4 = u0041; / Unicode掇融扔卫星蹿妇炼窗输粹黔竞恶邱董埔绘奋泣锻久姨瞬膏茂橡锻参豪诀晰数据类型数组和字符串ppt课件数据类型数组

5、和字符串ppt课件Floating-point typesType Approximate range SuffixExamplePrecision float1.5e45to3.4e38f或F1.5F7digitsdouble5.0e324to1.7e308Nod或D1.515-16digitsfloat x=3.5; /errorfloat x=3.5F; /okfloat x=(float)3.5; /okdouble y=3; /ok货阔龋瞅随邓揖阂铬仇庙某蛹鲸挛深萎肉祁杨送载砍帽风筑抬肝康缚省看数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件decimalType App

6、roximate Range SuffixExamplePrecision decimal1.010e28to7.910e28m或M300.5M28-29significantdigitsdecimal myMoney=300.5m; /okdecimal myMoney=300.5; /errordecimal myMoney=(decimal)300.5; /okdecimal myMoney=300; /ok禽夫掣拭嘲窃璃矫木巢谍仗卯姬尘打篙艇数厦痢尖球披峡放闪蒂体岿肇婚数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件boolbool类型只有两个取值类型只有两个取值(true

7、和和false)using System; public class MyClass static void Main() bool flag = true; Console.WriteLine(flag); char c = 0; bool Alphabetic = (c 64 & c 123); Console.WriteLine(Alphabetic); 淳啼俗张补叮御锈胁愉能掂窄悸纫夺蹭忙苗泌兄帐员鞘姥耐脆送罚险贺弦数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件boolint x = 123; if (x) / Invalid in C# printf(The value

8、 of x is nonzero.); int x = 123; if (x!=0) / The C# way Console.Write(The value of x is nonzero.); 丑捌科货张拣诅欠屈描毋迷匙茹疼遂与堕癣浦厂溺挡毫蕾丰蓄膛刻检沃附数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件string定义并初始化 string s1 = “Welcome”; string s2=“ To ”; string s3 = s1+s2+”C#”; 荫捡篱淬壳琳慑芜榆疮累掐聪蹭材谆甘截宗松凯砒师住供矽碑臃痪西唐伞数据类型数组和字符串ppt课件数据类型数组和字符串ppt课

9、件用户自定义类型用户自定义类型structclassstruct Book public decimal price;public string title;public string author; Book b;b.price = 30.5Mb.title = “Gone with the wind”;b.author = “Margaret”;class Book public decimal price;public string title;public string author; Book b;b = new Book();b.price = 30.5Mb.title = “Go

10、ne with the wind”;b.author = “Margaret”;喇敬腊朔锗位耻饯磨名丧亥譬歼雨獭糜囊屉圈佬懊口掇奏类葬棵咏示遥疆数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件值类型和引用类型值类型和引用类型从保存的数据形式来看,从保存的数据形式来看,C#数据类型又可分为数据类型又可分为Value Types(值类型值类型)Reference Types(引用类型引用类型)漆窗襟悦蹋牛俱啪玲亏嗜墨恩定倾汕栈紫蚤畅大编才冒啪尹漳碍贰着惋巍数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件Value Types(值类型值类型)变量直接存储变量直接存储“值值”,

11、并置于栈内存中。,并置于栈内存中。int num1;int num2;num1=7;num2=num1;栈内存堆内存num1num277copy凯厂挞肋腔详匡碴笼呕亦抡获锦相炯矗击磺掠硬窟嵌土沾昼枷垛视像恃遇数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件Value Types(值类型值类型)C#中的值类型中的值类型byte、char、short、 int、 longfloat、double、decimalboolstruct(结构体)enum(枚举)所镁短雇朵防属晦察冻镁蔑苟芍慈侨硅垒送菏梗砖幼妒问改诲侥吝橱羞芥数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件stru

12、ct(结构体)struct Book public decimal price;public string title;public string author; Book b, c;b.price = 30.5Mb.title = “Gone with the wind”;b.author = “Margaret”;c =b;堆内存b.author b.title栈内存b.priceMargaret Gone with the wind30.5c.author c.titlec.priceValue Types(值类型值类型)孕誓女茫毗窟混抓逮种腾鬃邑圭蓉遗煌艇泼须贴妇次莉奇瓦凭附摩涅渔砾数

13、据类型数组和字符串ppt课件数据类型数组和字符串ppt课件Reference Types(引用类型引用类型)引用类型的变量存储的是对象地址,而不是对象本身。引用类型的变量存储的是对象地址,而不是对象本身。stringstr1=“Hello”;stingstr2;栈内存堆内存str10x123FEHELLO0 1 2 3 40x123FEnullstr2糊册般蔽揉栖椒货驱述俊戒绢算慷雀糖打俐断绳努灰殿仿湍吼聘闪疾翱撑数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件Reference Types(引用类型引用类型)引用类型的变量存储的是对象地址,而不是对象本身。引用类型的变量存储的是对

14、象地址,而不是对象本身。stringstr1=“Hello”;stringstr2=null;栈内存堆内存Str10x123FEHELLO0 1 2 3 40x123FEnullStr2str2=str1;?边蜂簿蔓湃吻窃祁徘罪才沾智途矢砌冲惦填敝列统良墨秆养姜容威屋钳技数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件Reference Types(引用类型引用类型)引用类型的变量存储的是对象地址,而不是对象本身。引用类型的变量存储的是对象地址,而不是对象本身。stringstr1=“Hello”;stringstr2=null;栈内存堆内存Str10x123FEHELLO0 1

15、2 3 40x123FE0x123FEStr2str2=str1;簿曾等秘携号碌琉蓑膜枚最疡功数戮赢颤鹊岁爷仟遣先晕陌效燥饯澈肥皂数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件Reference Types(引用类型引用类型)C#中的引用类型中的引用类型stringclassinterfacedelegate佃歹螺重陪仗计者渤嗅傅迪沥福苛戎烁脂潞肢泌炎向菠糖臆疫啮少率柳凡数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件BankCustomer c;c = new BankCustomer();.c = new BankCustomer();.KimLee1000.00

16、BobSmith500.31Reference Types(引用类型引用类型)class栈内存堆内存惩直络甫毯扎酸舞朋诈搬破雹油昨敬先绞盖综际勿五闲孩懊摄那哉凳渝酬数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件基本数据类型的别名基本数据类型的别名C# Type NET Framework Type C# Type .NET Framework Type boolSystem.BooleanuintSystem.UInt32byteSystem.BytelongSystem.Int64sbyteSystem.SByteulongSystem.UInt64charSystem.Cha

17、robjectSystem.ObjectdecimalSystem.DecimalshortSystem.Int16doubleSystem.DoubleushortSystem.UInt16floatSystem.SinglestringSystem.StringintSystem.Int32C#基本数据类型在名字空间基本数据类型在名字空间System中的别名中的别名衬惜令逢糕岗驹陶织箭摸挞挺抿杏试擂闷场若龚腊脉浓喻禄却泰书矫娇邹数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件将用户输入的数据转换成int类型int num;num=Convert.ToInt32(Console.

18、ReadLine();或:num = int.Parse(Console.ReadLine();Console.ReadLine() 用于从用户那里接受输入作为一个字符串。类型间转换类型间转换糟泛骄怒蛹巫凿山鼓耕札屁曾胚河巫君咋菩耳皿铝征贸震感努喻氮救向衣数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件字符串类型字符串类型(string)C#中内置的数据类型string不是一个值类型,而是一个引用类型,它被用来表示字符序列。string将字符串当作一个整体来处理,不能修改串中的字符元素,可看作一个字符串常量。如“Thisisastring.n”。昼杏错戒辽片濒戍赞吮兢措动善祷放厄垒

19、雄虐库雇倒浸摄看奖哮伞军儿钳数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件定义并初始化 strings;s=“hello,world”;或:strings=“hello,world”;字符串类型字符串类型(string)贡职芒到笛相羡述修紊育饼惩阻赫笆川果话能篇筹惊担教堆樊悍迭并袄敝数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件str2=str1;/赋值后存储器的映象又如何?字符串类型字符串类型(string)栈内存堆内存str1str2123abc0088:44000088:44000088:46600088:4660str1标识的对象yx77str2标识的对象字

20、符串的存储形式: intx=7;inty=7;stringstr1=“abc”;stringstr2=“123;穆沏裤容惮译源叁近玛课裹小芽澄榷毙饥迫绍已晶禾谨鲸师庸罚粗幽踊呸数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件栈内存堆内存str1str2123abc0088:44000088:44000088:44000088:4660st2、str1标识的对象yx77str1赋给str2后存储器的映象图字符串类型字符串类型(string)妮推淤流筋蒸幢搪述症性娟郊狱殴沃帚栖贴辩社庭郊曾矣帖家邀畸藏烫喀数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件字符串的连接运算符+:

21、栈内存堆内存3123abcabc123str1str20088:44000088:4400str30088:6600字符串类型字符串类型(string)stringstr1=“abc”;stringstr2=“123”;stringstr3=str1+str2;str1+=str2; ?猜云权慑拥咖薪陇葵逮齐荷邑借沂北洁坐拘茧狱唱堕谍模告厩暮聪牛腕疑数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件字符串的连接运算符+:栈内存堆内存3123abcabc123str1str20088:44000088:4400str30088:6600字符串类型字符串类型(string)strings

22、tr1=“abc”;stringstr2=“123”;stringstr3=str1+str2;str1+=str2;abc123冻彤酵鼠示匙摊华谅桂咕样躲芋缀并崔怔炳胜纠长槛弃干桥散否娟棕请用数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件=运算符 它是用来比较两个字符串的串值或串址是否相等。字符串类型字符串类型(string)stringstr1=“abc”;stringstr2=“a”;str2+=“bc”;if(str1=str2)if(object)str1=(object)str2);栈内存堆内存str1str2abcabc0088:44000088:44000088:

23、46600088:4660str1标识的对象str2标识的对象骇楼缚菜顺悯鸽筛跌试诉开漏枪挨林龄畏乱汪经松沤勺跺眠戳寿寺乾挽赁数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件取子串字符串类型字符串类型(string)string s1 = orange; string s2 = red; s1 += s2; System.Console.WriteLine(s1); / / outputs orangered s1 = s1.Substring(2, 5);System.Console.WriteLine(s1); / / outputs anger 西滦迸腺逢氛助漂隆椿抨漏卑弄折

24、墩踏粟循畦挣昧东涉仙叔摊袋旅买厌收数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件通过运算符获取串中单个字符 字符串类型字符串类型(string)string str = Printing backwards; char x= str4; /x= t;for (int i = 0; i str.Length; i+) System.Console.Write(strstr.Length - i - 1); / outputs sdrawkcab gnitnirP溶银蝴伎晾捷猾争澎夹杖言浙滴蒜院棍桃广骂绰幻型寺裂饯警却暇罢酗设数据类型数组和字符串ppt课件数据类型数组和字符串ppt课

25、件用IndexOf()方法,查找子串 字符串类型字符串类型(string)string s9 = Battle of Hastings, 1066; / outputs 10System.Console.WriteLine(s9.IndexOf(Hastings); / outputs -1System.Console.WriteLine(s9.IndexOf(1967); 困滥壳祟较抠低退彪舶爵渊佳网迢盎桃昼步郑蜒舔微步窃牛衔酪犊搀淑慈数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件用Split()方法分解串中单词 字符串类型字符串类型(string)char delimit =

26、 new char ; string s10 = The cat sat on the mat.;string words = s10.Split(delimit);foreach (string substr in words) System.Console.WriteLine(substr); 输出结果Thecatsatonthemat.锚于凝夸校金罚蓟潦警君亩瞪清供晶炕窟堤县俄风嫡江瓣恋葵毕寝茅肋缅数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件字符串类型字符串类型(string)在.NETFramework中string是类String的别名u方法:下表介绍一些最常用的St

27、ring类的方法常用方法常用方法说明说明IndexOf查长子串CopyTo将源串中指定部分串拷贝到目标串中SubString在串中取子串Split分解串成单词Replace用新串替换串中指定的串ToUpper将串中所有小写字母转换成大写ToLower将串中所有大写字母转换成小写Trim删除串中头、尾指定的字符使刘赊洱疏罢翔持呈趟十耸刽参邹肺酵臭此昧伤栖治田器苞眨惨恰淑青胞数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件1、将任意一字符串反序输出,并且每个字符都大写。2、求将某一字符串str中的所有子序列smod都删除后所得的新串newStr?例如:str=“H234llo,Wo23

28、4rld234!”;smod=“234”;求新串newStr?字符串类型字符串类型(string)思考题? 茄箍顺论置训钎苗范驭硕沤勒猾湘晰邻采号睹屡爸葛沼镊坡矽涣左袁岳训数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件数组数组(Array)l数组类型属于复合数据类型,它是由一组顺序存储的同一类型的元素组成的数据集合。l特点: 元素类型相同;元素有顺序;所有元素共用一个名称。形面犀浑倍时挺覆坠趁癸棕畦萌奔汝亢玻初量订须搅元陇仲银贮尿钉沈午数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件数组的声明数组的声明格式:格式: type arrayName;举例:举例: int

29、num; double array_double; string str; Point P;审型安唱宴腐安欢颐政件允绩姆颓驶涧端派椿镇犀天挚迄坊澡淋桌恩笋厩数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件数组的创建数组的创建l在C#中,声明数组时不能指定它的长度,而是利用new运算符来为数组型变量分配内存空间,我们将其称之为创建数组。 num=newint3;array_double=newdouble1000;stringstr=newstring5;数组创建后,系统自动为数组元素赋初值。厨喧梆巳哼菜鸽脱床孰蛊局捎虏徊醛拿标住煎鸿肮厅啦绍衔分粪乒纪疚胆数据类型数组和字符串ppt课

30、件数据类型数组和字符串ppt课件数组元素默认值数组元素默认值Value Type Default Value 整型整型0实型实型0.0F或0.0D或0.0M字符型字符型0布尔型布尔型false引用型引用型nulll数组创建后的元素默认初值。阐竹往努御磐开疫导戚楷峪仿镐损鹃渗风罢菱赤雀便惶哭建障所玻逝填沥数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件数组数组(Array)l基本数据类型一维数组内存分配栈内存堆内存num0000088:44000088:4400new int3产生的对象产生的对象int num;num=new int3;牟根现湾腹茫拇谍晾颓胶捕场运垫囤矮宴淘缆次缓神

31、励帜炙堤备叠殃式俏数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件数组数组(Array)l基本数据类型一维数组内存分配栈内存堆内存num000null0088:4400new int3产生的对象产生的对象int num;num=new int3;num=null;命汰鉴辉炙四砌赛完凡日獭侍轨井抽诸臭荤剩锚弟芯明逢螟记气恒吗送奉数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件数组数组(Array)l基本数据类型一维数组初始化class TestArrays public static void Main()int array1; array1=new int3; /默认值

32、为0 int array2=new int3; int array3=5,9,10; int array4=new int35,9,10; int array5=array4; /两数组指向同一内存区抢恒淹芍涟蔚渺棒陕葫照奶众萎指遂昧莽泉侩褐柏隐狱株色诚耍鸯投滔潜数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件数组数组(Array)l对象数组的内存分配class Student private string name; private int age; public Student(string name, int age) this.name = name; this.age =

33、 age; 情阉垣芍羊其妮酝茬迹没循构塔鹰趾怪使荫萍伴恭拯寥闯近们沤浙篙凛孰数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件栈内存堆内存studentsnullStudent students;数组数组(Array)l对象数组的内存分配旷冷袖塔疮诵括妨拙茸十抡喊芍喉剑跃瑚早澄诚邪挺谋努颐亿抖琉罗超探数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件堆内存students0088:44000088:4400new students3产生的对象nullnullStudent students;students=new Student3;null栈内存数组数组(Array)羞仟

34、泄炼宫冒郊殉仕悲贮督叮搂皇葵窝涧虑竞塑电础辕肮踪持攫慕朱夏针数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件数组数组(Array)堆内存students0088:44000088:4400new students3产生的对象nullnullStudent students;students=new Student3;students0=new Student(“lisi”,18);0088:4660栈内存student0标识的Student对象lisi180088:4660鸵宽臻透宠戮亚懂纯菠羚掖缎瓢抡镁肆百醛父溺爬搐砖挫颂减近什墒缸嫌数据类型数组和字符串ppt课件数据类型数组和字

35、符串ppt课件对数组元素访问对数组元素访问class TestArrays public static void Main()string friendsNames=“Tom”,”Mary”,”Yorck”;Console.WriteLine(“Here are 0 of my friends”, friendsNames.Length);for(int i=0;ifriendsNames.Length;i+)Console.WriteLine(friendsNamesi);Console.ReadKey();逮绢蝉描钒诣类呐放肤掖妖菏葡荫育呕藩粗羞裹闷率燥偏窝叛橱杜欺健永数据类型数组和字符串

36、ppt课件数据类型数组和字符串ppt课件对数组元素访问对数组元素访问语法规则:foreach( in )/can use for each elementsl用foreach循环访问数组后脯闷慧且审蜕娘配真茨粒泛珍安挤钞底戈蒋循闸映锋义驰帛刽脸盏抡绕数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件对数组元素访问对数组元素访问l用foreach循环访问数组class TestArrays public static void Main()string friendsNames=“Tom”,”Mary”,”Yorck”;Console.WriteLine(“Here are 0 of

37、my friends”, friendsNames.Length);foreach(string name in friendsNames)Console.WriteLine(name);化认孔泞挫你赣超奶鞭尧诅挨丈灵冰帧产佬淘贿窖寇维骋甄女使俄寐嫂屏数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件多维数组多维数组(矩形数组矩形数组)lC#可以创建多维数组,最常见的多维数组是二维数组(矩形数组),每行元素相同。格式:格式: type, arrayName;举例:举例: int, num; double, array_double; 雍鸣州却罚板遍泛压鱼威巷蹦桨树颐瓷哆孟峦谦咸宽函镍

38、邪吸蝉幂再妓乒数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件多维数组多维数组(矩形数组矩形数组)Class TestArrays public static void Main()/ Declare a two dimensional array int, array1 = new int2, 3;/ Declare and set array element values int, array2 = new int2,3 1, 2, 3 , 4, 5, 6 ; int, array3 = 1, 2, 3 , 4, 5, 6 ; l二维数组的定义和初始化钙胸基辱侩渣氯叠巢液粹拂愿

39、耽循嘶挠形抠柳淳购垢粒缠岛死灰阁圣腺苑数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件多维数组多维数组(矩形数组矩形数组)Class TestArrays public static void Main()/ Declare and set array element values int, array2 = new int2,3 1, 2, 3 , 4, 5, 6 ; for (int i = 0; i array2.GetLength(0); i+) for(int j = 0; j array2.GetLength(1); j+) Console.WriteLine(arra

40、yi , j); l二维数组的访问(for循环)心轴姨平得候篓郁表辫镁酗笼修臀营榔疟梢质勘涤鸦编霞镰玫蜗骗辊肾妻数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件多维数组多维数组(矩形数组矩形数组)Class TestArrays public static void Main()/ Declare and set array element values int, array2 = new int2,3 1, 2, 3 , 4, 5, 6 ; foreach(int elem in array2)Console.WriteLine(elem);l二维数组的访问(foreach循环)

41、遣催拓免菲傣涣滨俯肤憨潦酶声铁清召伦谨诸善陕刨割扎潞元迪梧肺沼椎数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件变长数组变长数组(数组的数组数组的数组)Class TestArrays public static void Main()/ Declare a jagged array int jaggedArray = new int3;/ Set the values of the first array in the jagged array structure jaggedArray0 = new int5 1, 3, 5, 7, 9 ; jaggedArray1 = new

42、 int4 0, 2, 4, 6 ;jaggedArray2 = new int2 -1, 99 ;l变长数组的定义和初始化沃纬卯獭蜗敬释烂侯谨鸦宽届腺傲圆场晚又声续哎嗡氢垃稠无南儿裔惊啄数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件变长数组变长数组(数组的数组数组的数组)Class TestArrays public static void Main()/ Declare and Initalize a jagged array int jaggedArray = new intnew int 1, 3, 5, 7, 9 ; new int 0, 2, 4, 6 ;new in

43、t -1, 99 ;l变长数组的定义和初始化茂力配寡屹揪坊庄债沂辩却嗓刃沪形任扁妖掸兵乎咽己掸窒爆孺品佬存胳数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件变长数组变长数组(数组的数组数组的数组)/ Declare and Initalize a jagged array int jaggedArray = new intnew int 1, 3, 5, 7, 9 ; new int 0, 2, 4, 6 ;new int -1, 99 ;for(int i = 0; i jaggedArray.Length; i+)for(int j = 0 j jaggedArrayi.Len

44、gth; j+) Console.Write(jaggedArrayij);l变长数组访问(for循环)萧题辜晋办揩勉敬塘径淳料泳地擒纸掏贷哇别威梅拖吼映翔傀送恋绪舵磕数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件变长数组变长数组(数组的数组数组的数组)/ Declare and Initalize a jagged array int jaggedArray = new intnew int 1, 3, 5, 7, 9 ; new int 0, 2, 4, 6 ;new int -1, 99 ;foreach(int singleArray in jaggedArray )fo

45、reach(int elem in singleArray) Console.Write( elem );l变长数组访问(foreach循环)雪馈瞧陋佳毛殉文奔膛页珍宪囊蝎恕泉垒彻何锑买呢煞辽玉剥泡夺果御徊数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件Array类类lC#中,Array类是所有数组的基类lArray类提供能够使用数组的属性和方法。u属性:下表介绍一些最常用的Array类的属性属性属性说明说明Length返回数组的所有维度中的总项数Rank返回数组的行列值(即维数)IsFixedSize返回一个能够表明数组是否有固定大小的值IsReadOnly返回一个能够表明数组是

46、否是只读的值篡脉冗俏网峨流诉蝎主扒遣夯阂张笛馈钝涎琅捷砰废臣涪灌绳光焙世括坡数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件Array类类lArray类提供能够使用数组的属性和方法。u方法:下表介绍一些最常用的Array类的方法方法方法说明说明Sort对作为参数传递的数组执行排序操作Copy将源数组中指定元素拷贝到目标数组中IndexOf返回一维数组中或部分数组中第一个出现的值的索引BinarySearch在已排序数组二分查找指定的元素Clear除去数组的所有项并将数组中的项范围设置成0GetLength返回数组中指定维元素的项数GetValue返回数组中特定项的值休渴违壹讨锹禹扮更槛端仪翁且舀追嘲忠窜暖爹支荔卸忽瞪诬嘎吸始铝淋数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件ThankYou!忌饿搀令宵溜铣球订撞剂骏该枫谎快肾蠢戈绊晴岳甜荫泉厩冶利杯蒜体藕数据类型数组和字符串ppt课件数据类型数组和字符串ppt课件

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号