码迷,mamicode.com
首页 > Windows程序 > 详细

c# List去重

时间:2017-08-22 19:08:54      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:ati   tin   des   输出   div   log   ++   move   nbsp   

 public static void Purge(ref List<string> needToPurge)
        {

            for (int i = 0; i < needToPurge.Count - 1; i++)
            {
                string deststring = needToPurge[i];
                for (int j = i + 1; j < needToPurge.Count; j++)
                {
                    if (deststring.CompareTo(needToPurge[j]) == 0)
                    {
                        needToPurge.RemoveAt(j);
                        j--;
                        continue;
                    }
                }
            }
        }

使用:

  List<string> list = new List<string>();
            list.Add("1");
            list.Add("1");
            list.Add("2");
            list.Add("1");
            list.Add("3");
            list.Add("3");
            Purge(ref list);

//输出:

//1 、2、3

c# List去重

标签:ati   tin   des   输出   div   log   ++   move   nbsp   

原文地址:http://www.cnblogs.com/gaocong/p/7413086.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!