C# 数组学习

一、Array和ArrayLIst的区别

Array的容量是固定的,而ArrayList的容量可根据需要自动扩充.
ArrayList提供添加、插入或移除某一范围元素的方法。在Array中,你只能一次获取或设置一个元素的值。
Array可以具有多个维度,而ArrayList始终只是一维的。

二、二维数组学习
要得到下面的数组,在C#中如何写代码?

arr

0-5

0-3

11

12

13

14

15

16

21

22

23

24

25

26

31

32

33

34

35

36

41

42

43

44

45

46


代码:
using System;

class Matrix
{
    
static void Main()
    {
        
int[,] arr=new int[4,6];
        
for(int i=0;i<4;i++)
        {
            
for(int j=0;j<6;j++)
            {
                arr[i,j]
=(i+1)*10+j+1;
            }
        }
        
for(int i=0;i<4;i++)
        {
            
for(int j=0;j<6;j++)
            {
                Console.Write(
"{0}",arr[i,j]);
            }
            Console.WriteLine();
        }
        Console.ReadLine();
    }
}
原文地址:https://www.cnblogs.com/scottckt/p/1138633.html