C#中数组的指定维中的元素总数
要获取数组指定维度中的元素总数,代码如下-
示例
using System;
public class Demo {
public static void Main() {
string[] products = new string[] { "Andy", "Mark", "Gary", "Andre"};
Console.WriteLine("One or more name begins with 'A'? = {0}",
Array.Exists(products, ele => ele.StartsWith("A")));
Console.WriteLine("Is the array having fixed size? = " + products.IsFixedSize);
Console.WriteLine("Is the array read only? = " + products.IsReadOnly);
Console.WriteLine("Is the array synchronized? = " + products.IsSynchronized);
Console.WriteLine("Index of the 1st element = "+products.GetLowerBound(0));
Console.WriteLine("Index of the last element = "+products.GetUpperBound(0));
Console.WriteLine("GetLongLength(0) = "+products.GetLongLength(0));
}
}输出结果
这将产生以下输出-
One or more name begins with 'A'? = True Is the array having fixed size? = True Is the array read only? = False Is the array synchronized? = False Index of the 1st element = 0 Index of the last element = 3 GetLongLength(0) = 4
现在让我们来看另一个示例-
示例
using System;
public class Demo {
public static void Main() {
string[,, ] stdNames = new string[,, ] {
{ { "John", "Gary" },
{ "Jacob", "Harry" } },
{ { "Kevin", "Ryan" },
{ "David", "Mark" } },};
Console.WriteLine("Is the array having fixed size? = " + stdNames.IsFixedSize);
Console.WriteLine("Is the array read only? = " + stdNames.IsReadOnly);
Console.WriteLine("Is the array synchronized? = " + stdNames.IsSynchronized);
Console.WriteLine("Index of the 1st element = "+stdNames.GetLowerBound(0));
Console.WriteLine("Index of the last element = "+stdNames.GetUpperBound(0));
Console.WriteLine("GetLongLength(0) = "+stdNames.GetLongLength(0));
Console.WriteLine("GetLongLength(0) = "+stdNames.GetLongLength(1));
}
}输出结果
这将产生以下输出-
Is the array having fixed size? = True Is the array read only? = False Is the array synchronized? = False Index of the 1st element = 0 Index of the last element = 1 GetLongLength(0) = 2 GetLongLength(0) = 2
热门推荐
10 广西考试祝福语结婚简短
11 猪年祝福语简短小孩
12 元旦祝福语送长辈简短
13 恭喜二宝祝福语简短
14 祝福语暖心话简短
15 国庆中秋祝福语简短兄弟
16 朋友订婚的祝福语简短
17 送弟弟中秋祝福语简短
18 爱生日祝福语简短独特