
正文
C#数组维数及不同维数中元素个数的获取
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
简单理解有关数组维数的概念:
1、编程中用到的多维的数组,最多也就是二维数组了
2、数组的维数从0开始计算
using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Security.Cryptography;
using System.Text; namespace myMethod
{
class lgs
{
static void Main()
{
int[] array0 = new int[] { , , , };
int[,] array1 = new int[,] { { , , }, { , , } }; //注意:嵌套数组的维数需要一致 //打印数组的维数
Console.WriteLine(array0.Rank); //
Console.WriteLine(array1.Rank); // 2 //打印不同维中的元素个数,这里需要注意下数组的维数应该如何理解
Console.WriteLine(array0.GetLength()); //第一维的元素个数 4
Console.WriteLine(array1.GetLength()); //第一维的元素个数 2
Console.WriteLine(array1.GetLength()); //第二维的元素个数 3 Console.ReadKey();
}
}
}




