《C#入門經典第五版》數組

來源:互聯網
上載者:User

標籤:style   blog   color   使用   ar   for   sp   div   on   

一、數組 第115頁

//格式 :<basetype>[] <name>;//初始化方法一int[] myIntArry = new int[5]{1,2,3,4,5} ;//初始化方法二int[] myIntArry;myIntArry = new int[5];//初始化方法三  (如果使用變數定義數組範圍,該變數必須是常量,如下省略關鍵字const側編譯失敗)const int arrySize =5;int[] myIntArry = new int[arrySize] {1,2,3,4,5};

 

二、多維陣列、矩形數組

//二維數組<basetype>[,] <name> ;//四維數組<basetype>[,,,] <name>;//初始化方法一 :三行四列double[,] hillheight = new double[3,4]; //初始化方法二double[,] hillheight = {{1,2,3,4},{2,3,4,5},{5,6,7,8,}};

三、鋸齒數組、子數組

//初始化方法一:jaggedIntArry = new [2][];jaggedIntArry[0] = new int[3];jaggedIntArry[1] = new int[4];//初始化方法二:jaggedIntArry = new int[2][]{new int[]{1,2,3},new int[]{1,2,3,4}};//初始化方法三:int[][] jaggedIntArry = {new int[]{1,2,3},new int[]{1,2,3,4}};

 

 

數組的定位:

 

//foreach唯讀foreach (<basetype><name> in <arry>){//Console.WriteLine{"{0}",name};}//for 可寫入for (i = 0; i<= <name>.Length;i++ ){//Console.WriteLine{<name>[i]}}//多維陣列定位   定位到x列y行<name>[x,y]//子數組定位foreach {<basetype>[] <name1> in <arry>}{  foreach (<basetype> <name2> in <name1>)  {  Console.WriteLine(name2);  }}

 

《C#入門經典第五版》數組

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.