
- 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
C# program to remove duplicate elements from a List
Declare a list and add elements.
List<int> list = new List<int>(); list.Add(50); list.Add(90); list.Add(50); list.Add(100);
Now, use Distinct() method to get the unique elements only.
List<int> myList = list.Distinct().ToList();
The following is the complete code to remove duplicate elements from a List −
Example
using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List < int > list = new List < int > (); list.Add(50); list.Add(90); list.Add(50); list.Add(100); Console.WriteLine("Initial List..."); foreach(int a in list) { Console.WriteLine("{0}", a); } List < int > myList = list.Distinct().ToList(); Console.WriteLine("New List after removing duplicate elements..."); foreach(int a in myList) { Console.WriteLine("{0}", a); } } }
Output
Initial List... 50 90 50 100 New List after removing duplicate elements... 50 90 100
- Related Articles
- Python program to remove duplicate elements from a Circular Linked List
- Python program to remove duplicate elements from a Doubly Linked List\n
- Python Program to remove duplicate elements from a dictionary
- Java Program to Remove duplicate elements from ArrayList
- Python prorgam to remove duplicate elements index from other list
- Swift Program to Remove Duplicate Elements From an Array
- Golang Program To Remove Duplicate Elements From An Array
- Python program to remove Duplicates elements from a List?
- Java program to remove duplicates elements from a List
- Python Program to Remove Palindromic Elements from a List
- Program to find duplicate item from a list of elements in Python
- Golang program to remove elements from the linked list
- Program to remove duplicate entries in a list in Python
- Program to remove duplicate entries in a linked list in Python
- C# Program to remove duplicate characters from String

Advertisements