List<T> क्या है
एक List एक लचीला array है जो चीज़ें जोड़ने या हटाने पर बढ़ता और सिकुड़ता है। यह एक backpack जैसा है जो ज़्यादा किताबें रखने के लिए फैलता है।
In this page:
Syntax
List<type> listName = new List<type>();
listName.Add(item);
listName.Remove(item);
listName[0];
listName.Count;
List<T>
List<T> System.Collections.Generic से एक dynamically resizable collection है, fixed-size arrays के विपरीत। आप elements जोड़, हटा, और search कर सकते हैं, और यह ज़रूरत पड़ने पर अपने आप बढ़ता है। C# में यह सबसे आम तौर पर उपयोग होने वाली general-purpose collection है।
Note:
जब भी runtime पर elements की संख्या बदल सकती हो arrays से List<T> को प्राथमिकता दें।
उदाहरण: List<T>
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
List<string> names = new List<string> { "Amy", "Bo" };
names.Add("Cy");
names.Remove("Bo");
Console.WriteLine(names.Count);
foreach (string name in names)
{
Console.WriteLine(name);
}
}
}
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. #}
आम गलतियां
- किसी
foreachके अंदर किसी list से items हटाना, जोInvalidOperationExceptionफेंकता है। Countके बराबर एक index उपयोग करना, जोArgumentOutOfRangeExceptionफेंकता है।- implicit usings disabled होने पर
using System.Collections.Generic;भूल जाना।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: