C# में सूची घोषित करने और आरंभ करने के लिए, सबसे पहले सूची घोषित करें -
List<string> myList = new List<string>()
अब तत्व जोड़ें -
List<string> myList = new List<string>() {
"one",
"two",
"three",
}; इसके माध्यम से, हमने ऊपर छह तत्व जोड़े हैं।
C# में सूची घोषित करने और आरंभ करने के लिए पूरा कोड निम्नलिखित है -
उदाहरण
using System;
using System.Collections.Generic;
class Program {
static void Main() {
// Initializing collections
List<string> myList = new List<string>() {
"one",
"two",
"three",
"four",
"five",
"size"
};
Console.WriteLine(myList.Count);
}
} आउटपुट
6