基本语法和数组(二维,多维,交错数组)
生活随笔
收集整理的這篇文章主要介紹了
基本语法和数组(二维,多维,交错数组)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
class Program{static void Main(string[] args){// TestJiaoCuo();
Console.ReadKey();}//交錯數組.static void TestJiaoCuo(){//交錯數組. 交錯數組的本質是1個1維數組 只不過這個1維數組的元素又是數組,.int[][] arr = new int[3][];arr[0] = new int[3];arr[1] = new int[5];arr[2] = new int[4];Console.WriteLine(arr.Rank);//數組的維數 交錯數組是1Console.WriteLine(arr.Length);//長度是3//遍歷//foreach (int[] item in arr)//{// foreach (int i in item)// {// Console.WriteLine(i);// }//}for (int i = 0; i < arr.Length; i++){for (int j = 0; j < arr[i].Length; j++){Console.WriteLine(arr[i][j]);}}int[][][] arr1 = new int[3][][];}static void TestDuowei(){int[, ,] arr = new int[3, 4, 5];}static void TestIf(){int lwh = 900;if (lwh > 1000) //條件表達式或者是1個bool類型的變量
{Console.WriteLine("中午請吃飯.");}else if (lwh > 800){Console.WriteLine("中餐.");}else if (lwh > 500){Console.WriteLine("小餐.");}else{Console.WriteLine("大家請他吃飯....");}Console.WriteLine("這里是繼續往下的代碼...");}static void TestSwitch(){//switch只能判斷等值 ifelse可以判斷等值也可以判斷范圍.int score = 78;switch (score / 10){case 10:case 9:Console.WriteLine("A");break;case 90:Console.WriteLine("A");break;}}static void TestWhie(){//while (true)//{// Console.WriteLine("A");//}//do//{//}while(); for (int i = 0; i < 10; i++){Console.WriteLine("A");break;//
continue;}}static void Test2(){//二維數組表示1個表格 2行3列int[,] arr = new int[2, 3];//Length屬性代表數組的長度 行*列//Console.WriteLine(arr.Length);//Console.WriteLine(arr[1,1]); //得到指定維度的長度arr.GetLength(1);for (int i = 0; i < arr.GetLength(0); i++)//2{for (int j = 0; j < arr.GetLength(1); j++)//3{Console.WriteLine(arr[i, j]);}}Console.WriteLine("**************");Console.WriteLine(arr.Rank);//遍歷//foreach (int i in arr)//{// Console.WriteLine(i);//}
}}
?
轉載于:https://www.cnblogs.com/kongsq/p/5866726.html
總結
以上是生活随笔為你收集整理的基本语法和数组(二维,多维,交错数组)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 「架构师必备」关于网络优化你必须要知道的
- 下一篇: 清理localstorage_vue 界