關于二維數組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));
? ? ? ? }
括號里是0輸出2
括號里為1輸出3
求解
2018-11-03
對于二維數組的GetLength方法的參數,為0時獲取的是二維數組內一位數組的個數,也就是行數,為1時獲取的是列的個數,也就是每個一維數組內元素個數,類似我這個
?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
昨天才開始看C#,...多包涵
2018-11-03
GetLength(0)是計算二維數組的行數,GetLength(1)是計算二維數組的列數