luoyikun

导航

c#一个list去掉其中重复元素

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> list = new List<int>();
            list.Add(1);
            list.Add(2);
            list.Add(2);
            list.Add(3);
            list.Add(1);
            SameRemove(list);
        }
        public   static   void  SameRemove(List<int> list)   
        { 
           for  ( int  i  =   0 ; i  <  list.Count  -   1 ; i ++ )   
           {
               for (int j = list.Count - 1; j > i; j--)
               {
                   if (list[i] == list[j])
                   {
                       list.RemoveAt(j);
                   } 
                }
               
          }
           for (int i = 0; i < list.Count; i++)
           {
               Console.WriteLine(list[i] + " ");
           }
           Console.ReadLine();

        }
    }
}

posted on 2017-04-05 21:02  luoyikun  阅读(18)  评论(0)    收藏  举报  来源