c#資料結構(第二章)

來源:互聯網
上載者:User

做成思維導圖了~

ArrayList和數組

 

 

 

 

1,數組的聲明和執行個體化

View Code

Type[] Array-name資料類型[ ] 數組名;string[] names;names=new string[5];

2,數組元素的設定和存取訪問

View Code

SetValue方法name[2]="James";name.SetValue("James", 2)GetValue方法myname=name[2]myname=sales.GetValue(2)

 3,檢索數組中繼資料的方法和屬性

View Code

ArrayListLength:返回數組所有維數內元素的總數量;GetLength:返回數組指定維數內的總數量;Rank:返回數組的維數;Gettype:返回當前數組執行個體的類型;GetUpperBound(0)

4,多維陣列

View Code

int[,] sales=new int[12,30]static void Main(){  int[] Jan=new int[31];  int[] Feb=new int[29];  int[][] sales=new int[] []{Jan,Feb};  int mouth,day,total; double average=0.0; sales[0][0]=41; sales[0][1]=30 sales[0][2]=25 sales[0][3]=30 sales[0][4]=30 sales[0][5]=30 sales[0][6]=43 sales[1][0]=23; sales[1][1]=12 sales[1][2]=12 sales[1][3]=32 sales[1][4]=52 sales[1][5]=48 sales[1][6]=10   for(month=0;month<=1;month++)   {      total=0;      for(day=0;day<=6;day++)     {       total+=sales[month][day]     }     average=total/7;   }}

 ,5,參數數組

View Code

params int[]  做為參數數組進行傳遞static int sumNums(params int[] nums){ int sum=0;for(int i=0;i<=nums.GetUpperBound;i++){sum+=nums[i];}}

,6,鋸齒狀數組

View Code

鋸齒狀數組時一種每行都能組成一個數組,鋸齒狀數組的每一維就是一個一位元組int[][]  jagged=new int[12][ ]

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.