Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> C#

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(1) = " + 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(1) = 2

  1. - C# प्रोग्राम: सरणी में प्रारंभिक तत्वों को छोड़ना

    यदि आप सरणी में कई तत्वों को छोड़ना चाहते हैं, तो C# में Skip() मेथड का उपयोग करें।मान लीजिए निम्नलिखित हमारी सरणी है:int[] arr = { 24, 40, 55, 62, 70, 82, 89, 93, 98 };अब पहले चार तत्वों को छोड़ने के लिए:var ele = arr.Skip(4);आइए पूरा उदाहरण देखें:उदाहरणusing System.IO; using System; using System.L

  1. - C# प्रोग्राम: सरणी में बाइट्स की संख्या गिनें

    एक बाइट सरणी सेट करें: byte[] b = { 5, 9, 19, 23, 29, 35, 55, 78 }; बाइट्स की संख्या गिनने के लिए: Buffer.ByteLength(b) निम्न कोड है: उदाहरण using System; class Program { static void Main() { byte[] b = { 5, 9, 19, 23, 29, 35, 55, 78 }; int len = Buffer.ByteLength(b);

  1. - C# में ऐरे से एलिमेंट्स कैसे एक्सेस करें?

    सबसे पहले, ऐरे को परिभाषित और इनिशियलाइज़ करें:int[] p = new int[3] {99, 92, 95};अब, ऐरे एलिमेंट्स प्रदर्शित करें:for (j = 0; j < 3; j++) { Console.WriteLine(Price of Product[{0}] = {1}, j, p[j]); }किसी भी एलिमेंट को एक्सेस करने के लिए, बस उस एलिमेंट का इंडेक्स शामिल करें जिसे आप चाहते हैं:p[2];