作者smallco0420 (原由)
看板C_Sharp
标题Re: [请问] c# 如何取出阵列大小
时间Mon Jan 3 14:02:28 2011
※ 引述《nonebelieve (天)》之铭言:
: ※ [本文转录自 ask 看板 #1D7mR1Rx ]
: 作者: nonebelieve (天) 看板: ask
: 标题: [请问] c# 如何取出阵列大小
: 时间: Sat Jan 1 18:49:34 2011
: 在c++中
: int String[]={1,2,3,4,5};
: int Length=sizeof(String) / sizeof(String[0]);
: 这样子 就可以取出阵列大小的值 等於 5
: 在c# 如果像这样做的话
: 他会说 "变数宣告中不能指定阵列大小"
: 请问 该怎麽取呢?
: 感谢大家回答:)
string[] ss = { "1", "2", "3", "4", "5" };
int n = ss.Length; //取得阵列长度值
Console.WriteLine("阵列长度值为:{0}", n);
Console.Read();
OR
int[] ss = { 1, 2, 3, 4, 5 };
int n = ss.Length; //取得阵列长度值
Console.WriteLine("阵列长度值为:{0}", n);
Console.Read();
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 122.122.217.115