關(guān)于二維數(shù)組GetLength的用法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp8
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? int[,] text = new int[,]{ { 1, 2, 3 }, { 1, 2, 3 } };
? ? ? ? ? ? Console.Write(text.GetLength(1));
? ? ? ? }
括號(hào)里是0輸出2
括號(hào)里為1輸出3
求解
2018-11-03
對(duì)于二維數(shù)組的GetLength方法的參數(shù),為0時(shí)獲取的是二維數(shù)組內(nèi)一位數(shù)組的個(gè)數(shù),也就是行數(shù),為1時(shí)獲取的是列的個(gè)數(shù),也就是每個(gè)一維數(shù)組內(nèi)元素個(gè)數(shù),類似我這個(gè)
?int[,] text = { { 1, 2, 3, 4 }, { 1, 2, 3 ,4},{ 2,6,9,10} };
?Console.Write(text.GetLength(0));? ? 輸出3
?Console.Write(text.GetLength(1));? ? 輸出4
昨天才開(kāi)始看C#,...多包涵
2018-11-03
GetLength(0)是計(jì)算二維數(shù)組的行數(shù),GetLength(1)是計(jì)算二維數(shù)組的列數(shù)