要找到数组中第一个元素的索引,代码如下-
using System; public class Demo { public static void Main() { string[] products = new string[] { "Andy", "Mark", "Gary", "Andre"}; Console.WriteLine("One or more name begin with 'A'? = {0}", Array.Exists(products, ele => ele.StartsWith("A"))); Console.WriteLine("数组是否具有固定大小? = " + products.IsFixedSize); Console.WriteLine("数组是只读的吗? = " + products.IsReadOnly); Console.WriteLine("数组是否同步? = " + products.IsSynchronized); Console.WriteLine("第一个元素的索引 = "+products.GetLowerBound(0)); } }
输出结果
这将产生以下输出-
一个或多个数组元素以“ A”开头? = True 数组是否具有固定大小? = True 数组是只读的吗? = False Is the array synchronized? = False 第一个元素的索引 = 0
让我们看另一个例子-
using System; public class Demo { public static void Main() { string[] products = new string[] { }; Console.WriteLine("数组是否具有固定大小? = " + products.IsFixedSize); Console.WriteLine("数组是只读的吗? = " + products.IsReadOnly); Console.WriteLine("数组是否同步? = " + products.IsSynchronized); Console.WriteLine("第一个元素的索引 = "+products.GetLowerBound(0)); } }
输出结果
这将产生以下输出-
数组是否具有固定大小? = True 数组是只读的吗? = False 数组是否同步? = False 第一个元素的索引 = 0