Remove MethodΒΆ

Used to remove first instanace of a specific element from a list.

listName.Remove(element);

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
List<string> planets = new List<string>()
{
   "Mercury",
   "Venus",
   "Earth",
   "Mars",
   "Jupiter",
   "Saturn",
   "Uranus",
   "Neptune",
   "Pluto"
};


planets.Remove("Pluto");

foreach(string planet in planets)
{
   Console.WriteLine(planet);
}

Output

Mercury
Venus
Earth
Mars
Jupiter
Saturn
Uranus
Neptune

There are a few other Remove methods if you are interested.