← Back to C# Course | Chapter 9: Collections | Lesson 1 of 7

Arrays क्या हैं

एक array एक fixed size की एक जैसी type के boxes की पंक्ति है, हर एक का एक number जो zero से शुरू होता है। किसी egg carton की तरह, बनने के बाद आप और slots नहीं जोड़ सकते।

In this page:

  1. Arrays
Syntax
csharp
type[] arrayName = new type[length];
type[] arrayName = { value1, value2, value3 };

arrayName[0];        // first element
arrayName.Length;

Arrays

एक array एक fixed-size, ordered collection है एक जैसी type के elements का, जो 0 से indexed होता है। बनने के बाद, इसकी length नहीं बदल सकती। Arrays सबसे basic collection type हैं और आंतरिक रूप से कई ज़्यादा flexible collections के पीछे हैं।

Warning: array के bounds से बाहर किसी index को access करना runtime पर एक IndexOutOfRangeException फेंकता है।

उदाहरण: Arrays

markup
using System;

class Program
{
    static void Main(string[] args)
    {
        int[] numbers = { 10, 20, 30, 40 };

        Console.WriteLine(numbers.Length);
        Console.WriteLine(numbers[0]);
        numbers[1] = 99;

        foreach (int n in numbers)
        {
            Console.WriteLine(n);
        }
    }
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. arr[arr.Length] पढ़ना या लिखना, जबकि आखिरी valid index Length - 1 है, जो IndexOutOfRangeException फेंकता है।
  2. किसी array में एक element जोड़ने की कोशिश करना, जबकि बनने के बाद इसका size fixed है; उसके लिए List<T> का उपयोग करें।
  3. एक array को दूसरे को assign करना और एक copy की उम्मीद करना, जबकि दोनों variables एक ही array को refer करते हैं।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.