我有一个像这样的字符串列表:
{"100", "101, "101", "102, "103, "103", "104", "104", "105"}
我需要获得一个只有不同值的新字符串列表:
{"100","101","102","103","104","105"}
任何人都有快速的方法吗?
答案 0 :(得分:5)
您可以使用Distinct方法:
List<string> distinctList = dupeList.Distinct().ToList();
答案 1 :(得分:3)
List<String> strings = new List<string>() { "100", "101", "101", "102", "103", "103", "104", "104", "105" };
var distinctStrings = strings.Distinct().ToList();
答案 2 :(得分:0)
List<string> dupes = new List<string>(){"100", "101, "101", "102, "103, "103", "104", "104", "105"};
List<string> no_dupes = dupes.Distinct().ToList();
或者您可以使用HashSet
var noDupes = new HashSet<string>(dupes).ToList();