zoukankan      html  css  js  c++  java
  • C#数组维数及不同维数中元素个数的获取

    简单理解有关数组维数的概念:

    1、编程中用到的多维的数组,最多也就是二维数组了

    2、数组的维数从0开始计算

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Collections;
     4 using System.IO;
     5 using System.Security.Cryptography;
     6 using System.Text;
     7 
     8 namespace myMethod
     9 {
    10     class lgs
    11     {
    12         static void Main()
    13         {
    14             int[] array0 = new int[] { 1, 2, 3, 5 };
    15             int[,] array1 = new int[,] { { 1, 2, 3 }, { 4, 5, 6 } };  //注意:嵌套数组的维数需要一致
    16 
    17             //打印数组的维数
    18             Console.WriteLine(array0.Rank);     // 1
    19             Console.WriteLine(array1.Rank);     // 2
    20 
    21             //打印不同维中的元素个数,这里需要注意下数组的维数应该如何理解
    22             Console.WriteLine(array0.GetLength(0));     //第一维的元素个数  4
    23             Console.WriteLine(array1.GetLength(0));     //第一维的元素个数  2
    24             Console.WriteLine(array1.GetLength(1));     //第二维的元素个数  3
    25 
    26             Console.ReadKey();
    27         }
    28     }
    29 }
  • 相关阅读:
    Spring-AOP
    spring学习笔记
    费曼学习法:学习任何知识的好方法
    Spring学习
    Spring学习笔记
    Markdown学习(Typora)
    2020-07-16日报博客
    2020-07-15日报博客
    2020-07-14日报博客
    2020-07-13日报博客
  • 原文地址:https://www.cnblogs.com/luguoshuai/p/10005981.html
Copyright © 2011-2022 走看看