List
आइए देखें कि C# में Add() विधि का उपयोग कैसे करें।
उदाहरण
using System;
using System.Collections.Generic;
class Program {
static void Main() {
List<string> sports = new List<string>();
sports.Add("Football");
sports.Add("Tennis");
sports.Add("Soccer");
foreach (string s in sports) {
Console.WriteLine(s);
}
}
} आउटपुट
Football Tennis Soccer
आइए देखें कि C# में निकालें () विधि का उपयोग कैसे करें।
उदाहरण
using System;
using System.Collections.Generic;
class Program {
static void Main() {
List<string> sports = new List<string>();
sports.Add("Football"); // add method
sports.Add("Tennis");
sports.Add("Soccer");
Console.WriteLine("Old List...");
foreach (string s in sports) {
Console.WriteLine(s);
}
Console.WriteLine("New List...");
sports.Remove("Tennis"); // remove method
foreach (string s in sports) {
Console.WriteLine(s);
}
}
} आउटपुट
Old List... Football Tennis Soccer New List... Football Soccer