
- 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
How to remove an item from a C# list by using an index?
To remove an item from a list in C# using index, use the RemoveAt() method.
Firstly, set the list −
List<string> list1 = new List<string>() { "Hanks", "Lawrence", "Beckham", "Cooper", };
Now remove the element at 2nd position i.e. index 1
list1.RemoveAt(1);
Let us see the complete example −
Example
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { List<string> list1 = new List<string>() { "Hanks", "Lawrence", "Beckham", "Cooper", }; Console.Write("Initial list..."); foreach (string list in list1) { Console.WriteLine(list); } Console.Write("Removing element from the list..."); list1.RemoveAt(1); foreach (string list in list1) { Console.WriteLine(list); } } }
Output
Initial list... Hanks Lawrence Beckham Cooper Removing element from the list... Hanks Beckham Cooper
- Related Articles
- How to insert an item into a C# list by using an index?
- How to remove an element from a list by index in Python?
- How to remove an item from an ArrayList in C#?
- How to remove an item from JavaScript array by value?
- Remove an item from a Hashtable in C#
- C# program to remove an item from Set
- How to remove an item from an ArrayList in Kotlin?
- How to remove an item from a C++ STL vector with a certain value?
- How to find the index of an item in a C# list in a single step?
- How to select an item from a dropdown list using Selenium WebDriver with java?
- How to remove an element from Array List in C#?
- How to remove an element from a Java List?
- How can I remove a specific item from an array JavaScript?
- How to find the index of an item given a list containing it in Python?
- How to remove index list from another list in python?

Advertisements