我有一個字符串像這樣的列表:獲取唯一值
{"100", "101, "101", "102, "103, "103", "104", "104", "105"}
我需要得到一個新的字符串列表,只有不同的值:
{"100","101","102","103","104","105"}
任何人都有一個快速的方法來做到這一點?
我有一個字符串像這樣的列表:獲取唯一值
{"100", "101, "101", "102, "103, "103", "104", "104", "105"}
我需要得到一個新的字符串列表,只有不同的值:
{"100","101","102","103","104","105"}
任何人都有一個快速的方法來做到這一點?
List<String> strings = new List<string>() { "100", "101", "101", "102", "103", "103", "104", "104", "105" };
var distinctStrings = strings.Distinct().ToList();
您可以使用DISTINCT方法:
List<string> distinctList = dupeList.Distinct().ToList();
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();
可能DUPLI這個問題的解答: http://stackoverflow.com/questions/292307/selecting-unique-elements-from-a-list-in-c – yas4891 2011-05-24 17:03:51