Click here to Skip to main content
15,917,481 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
old list :
XML
List<int> OLd = new List<int>() { 1, 1, 1, 1, 1, 1, 1, 2, 2 };

XML
List<int> New = new List<int>() { 1, 2 };
Posted

try with the following code:

C#
List <int> OLd = new List<int>() { 1, 1, 1, 1, 1, 1, 1, 2, 2 };
List<int> New = OLd.Distinct().ToList();
 
Share this answer
 
v2
I suggest to create a method for adding the values and add a check in the method before adding that value.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900