在C#陣列中查詢第一個元素的索引
若要查詢陣列中第一個元素的索引,程式碼如下 -
示例
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("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));
}
}輸出
將生成以下輸出 -
One or more name begin 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
示例
讓我們看另一個示例 -
using System;
public class Demo {
public static void Main() {
string[] products = new string[] { };
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));
}
}輸出
將生成以下輸出 -
Is the array having fixed size? = True Is the array read only? = False Is the array synchronized? = False Index of the 1st element = 0
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP