Re: [請問] c# 如何取出陣列大小

看板C_Sharp作者 (原由)時間15年前 (2011/01/03 14:02), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《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
文章代碼(AID): #1D8MPtQ_ (C_Sharp)
文章代碼(AID): #1D8MPtQ_ (C_Sharp)