lst={1,2,3,4,1,2}
如何处理成
lst={1,2,3,4}见笑了,谢谢解答。

解决方案 »

  1.   

     List<int> list = new List<int>() { 1, 2, 2, 3, 4, 2, 4, 3, 1 };
                list = list.Distinct().ToList();
                //以上为C#3.0版本以上可用            //以下为C#2.0可用
                List<int> a = new List<int>();
                a.Add(1);
                a.Add(2);
                a.Add(3);
                a.Add(3);
                a.Add(2);
                a.Add(2);
                a.Add(2);
                a.Add(3);
                for (int i = a.Count - 1; i >= 0; i--)
                    if (a.IndexOf(a[i]) != i)
                        a.RemoveAt(i);
                foreach (int i in a)
                    Console.WriteLine(i);
           
      

  2.   

       List<int> list = new List<int>() { 1, 2, 2, 3, 4, 2, 4, 3, 1 };
                    list = list.Distinct().ToList();
                    /*
                     *  [0] 1 int
                    [1] 2 int
                    [2] 3 int
                    [3] 4 int                 */