
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What are Add, Remove methods in C# lists?
The List<T> is a collection in C# and is a generic collection. The add and remove methods are used in C# lists for adding and removing elements.
Let us see how to use Add() method in C#.
Example
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); } } }
Output
Football Tennis Soccer
Let us see how to use Remove() method in C#.
Example
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); } } }
Output
Old List... Football Tennis Soccer New List... Football Soccer
- Related Articles
- What are generic methods in C#?
- What are anonymous methods in C#?
- What are Lists and Self-Organizing lists in compiler design?
- What are different methods of passing parameters in C#?
- What are methods in Java?
- What are defender methods or virtual methods in Java?
- Remove duplicate lists in tuples (Preserving Order) in Python
- What is the difference between del, remove and pop on lists in python ?
- How to use Remove, RemoveAt, RemoveRange methods in C# list collections?
- How do you add two lists in Java?
- Difference Between Del and Remove() on Lists in Python?
- what are abstract methods in Java?
- What are vararg methods in Java?
- What are Event Methods in jQuery?
- What are async methods in JavaScript?

Advertisements