List<T> C# में एक Collection है और यह एक Generic Collection है। Add और Remove Methods का उपयोग C# Lists में Elements को Add और Remove करने के लिए किया जाता है।
आइए देखते हैं कि C# में Add() Method का उपयोग कैसे करें।
Example
using System; using System.Collections.Generic; class Program { static void Main() { List sports = new List(); sports.Add("Football"); sports.Add("Tennis"); sports.Add("Soccer"); foreach (string s in sports) { Console.WriteLine(s); } } } Output
Football Tennis Soccer
आइए देखते हैं कि C# में Remove() Method का उपयोग कैसे करें।
Example
using System; using System.Collections.Generic; class Program { static void Main() { List sports = new List(); 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); } } } Output
Old List... Football Tennis Soccer New List... Football Soccer