ऐरे के पहले एलिमेंट का इंडेक्स प्राप्त करने के लिए Array.GetLowerBound(0) मेथड का उपयोग करें।
सिंटैक्स
public int GetLowerBound(int dimension);
पैरामीटर dimension शून्य-आधारित डायमेंशन है (0 = पहला डायमेंशन)।
उदाहरण 1: एलिमेंट्स के साथ ऐरे
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
उदाहरण 2: खाली ऐरे
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
महत्वपूर्ण बिंदु
- C# में ऐरे हमेशा शून्य-आधारित होते हैं →
GetLowerBound(0)हमेशा0लौटाता है - यह मेथड मल्टीडायमेंशनल ऐरे के लिए अधिक उपयोगी है
GetUpperBound(dimension)अंतिम इंडेक्स लौटाता हैLengthप्रॉपर्टी कुल एलिमेंट्स देता है
मल्टीडायमेंशनल ऐरे उदाहरण
int[,] matrix = new int[3, 4]; // 3 पंक्तियाँ, 4 कॉलम
Console.WriteLine("Dimension 0 lower: " + matrix.GetLowerBound(0)); // 0
Console.WriteLine("Dimension 0 upper: " + matrix.GetUpperBound(0)); // 2
Console.WriteLine("Dimension 1 lower: " + matrix.GetLowerBound(1)); // 0
Console.WriteLine("Dimension 1 upper: " + matrix.GetUpperBound(1)); // 3
// कुल एलिमेंट्स
Console.WriteLine("Total elements: " + matrix.Length); // 12
ऐरे गुण सारांश
| गुण/मेथड | विवरण | उदाहरण मान |
|---|---|---|
GetLowerBound(0) | पहले डायमेंशन का पहला इंडेक्स | 0 |
GetUpperBound(0) | पहले डायमेंशन का अंतिम इंडेक्स | Length - 1 |
Length | सभी डायमेंशन्स में कुल एलिमेंट्स | 12 |
Rank | डायमेंशन्स की संख्या | 2 |
IsFixedSize | हमेशा true (C# ऐरे) | True |
IsReadOnly | हमेशा false | False |
IsSynchronized | थ्रेड-सेफ है? | False |