c#去除List中的重复项

List<string> list = new List<string> {"a", "a", "b", "b", "c", "c"}
//(1)
var varNew = new HashSet<string> (list);
foreach (string item in varNew) {
    Debug.Log ("item = " + item);
}
/*
item = a
item = b
item = c
*/

//(2)
var varNew1 = list.Distinct ().ToList ();
foreach (string item in varNew1) {
    Debug.Log ("item = " + item);
}
/*
item = a
item = b
item = c
*/

 

posted @ 2015-08-07 10:12  YYRise  阅读(1509)  评论(0编辑  收藏  举报