C# Array.Length屬性代碼示例- 純淨天空
文章推薦指數: 80 %
C# Array.Length屬性代碼示例,System.Array.Length用法.
當前位置:首頁>>代碼示例>>C#>>正文
本文整理匯總了C#中System.Array.Length屬性的典型用法代碼示例。
如果您正苦於以下問題:C#Array.Length屬性的具體用法?C#Array.Length怎麽用?C#Array.Length使用的例子?那麽恭喜您,這裏精選的屬性代碼示例或許可以為您提供幫助。
您也可以進一步了解該屬性所在類System.Array的用法示例。
在下文中一共展示了Array.Length屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。
您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的C#代碼示例。
示例1:Main
▲點讚13
▼
//引入命名空間
usingSystem;
publicclassExample
{
publicstaticvoidMain()
{
//Declareasingle-dimensionalstringarray
String[]array1d={"zero","one","two","three"};
ShowArrayInfo(array1d);
//Declareatwo-dimensionalstringarray
String[,]array2d={{"zero","0"},{"one","1"},
{"two","2"},{"three","3"},
{"four","4"},{"five","5"}};
ShowArrayInfo(array2d);
//Declareathree-dimensionalintegerarray
int[,,]array3d=newint[,,]{{{1,2,3},{4,5,6}},
{{7,8,9},{10,11,12}}};
ShowArrayInfo(array3d);
}
privatestaticvoidShowArrayInfo(Arrayarr)
{
Console.WriteLine("LengthofArray:{0,3}",arr.Length);
Console.WriteLine("NumberofDimensions:{0,3}",arr.Rank);
//Formultidimensionalarrays,shownumberofelementsineachdimension.
if(arr.Rank>1){
for(intdimension=1;dimension<=arr.Rank;dimension++)
Console.WriteLine("Dimension{0}:{1,3}",dimension,
arr.GetUpperBound(dimension-1)+1);
}
Console.WriteLine();
}
}開發者ID:.NET開發者,項目名稱:System,代碼行數:36,代碼來源:Array.Length輸出:
LengthofArray:4
NumberofDimensions:1
LengthofArray:12
NumberofDimensions:2
Dimension1:6
Dimension2:2
LengthofArray:12
NumberofDimensions:3
Dimension1:2
Dimension2:2
Dimension3:3
示例2:Main
▲點讚13
▼
//引入命名空間
usingSystem;
classMainClass{
publicstaticvoidMain(){
int[,,]nums=newint[10,5,6];
Console.WriteLine("Lengthofnumsis"+nums.Length);
}
}開發者ID:C#程序員,項目名稱:System,代碼行數:11,代碼來源:Array.Length
注:本文中的System.Array.Length屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。
相關方法
Array.IsSynchronized
Array.Length
Array.Rank
Array.SyncRoot
Array.AsReadOnly()
Array.BinarySearch()
Array.Clear()
Array.Clone()
Array.ConvertAll()
Array.Copy()
Array.CopyTo()
Array.CreateInstance()
Array.Exists()
Array.Find()
Array.FindAll()
Array.FindIndex()
Array.FindLast()
Array.FindLastIndex()
Array.ForEach()
Array.GetEnumerator()
Array.GetLength()
Array.GetLowerBound()
Array.GetUpperBound()
Array.GetValue()
Array.IndexOf()
Array.LastIndexOf()
Array.Resize()
Array.Reverse()
Array.SetValue()
Array.Sort()
Array.TrueForAll()
延伸文章資訊
- 1How to get the length of a multidimensional array in C# ...
To get the length of a multidimensional (row/column) array, we can use the Array.GetLength() meth...
- 2How to find the length of an Array in C# - GeeksforGeeks
Array.Length Property is used to get the total number of elements in all the dimensions of the Ar...
- 3Get the Length of an Array in C# | Delft Stack
- 4C# Array length - Linux Hint
If faced with that situation, C# length functions can be an essential to let you know about the e...
- 5Working With Arrays In C#