Arrays क्या हैं
एक array एक fixed size की एक जैसी type के boxes की पंक्ति है, हर एक का एक number जो zero से शुरू होता है। किसी egg carton की तरह, बनने के बाद आप और slots नहीं जोड़ सकते।
In this page:
Syntax
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
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);
}
}
}
Login to try C/C++/Java/PHP code in the editor
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. #}
आम गलतियां
arr[arr.Length]पढ़ना या लिखना, जबकि आखिरी valid indexLength - 1है, जोIndexOutOfRangeExceptionफेंकता है।- किसी array में एक element जोड़ने की कोशिश करना, जबकि बनने के बाद इसका size fixed है; उसके लिए
List<T>का उपयोग करें। - एक array को दूसरे को assign करना और एक copy की उम्मीद करना, जबकि दोनों variables एक ही array को refer करते हैं।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: