不要告诉我倒进hashtable再倒回来

解决方案 »

  1.   


    List<string> list= GetList();//get data
    List<string> resultList=list.Find(PredicateItems);//PredicateItems是个委托        private bool PredicateItems(item targetItem)
            {
                if (targetItem.itemID == _itemID)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
      

  2.   


    List<int> array = new List<int>();array.Add(1);array.Add(2);array.Add(3);array.Add(1);
    array.Add(2);for (int i = array.Count - 1; i >= 0; --i)  {if (array.IndexOf(array[i]) != i)    array.RemoveAt(i);
    }string类似
      

  3.   

    类似插入排序,创建一个新的List,然后遍历当前list一项一项往里添加,如果某项已存在则不往里添加。
      

  4.   

    先排序,然后遍历添加到新的List<String>中去。
      

  5.   

    List<string> list = new List<string>();
      var c = (from li in list
      select li).Distinct();
      

  6.   

      public List<int> GetLists()
        {
            List<int> array = new List<int>();
            array.Add(1);
            array.Add(2);
            array.Add(3);
            array.Add(4);
            array.Add(1);
            array.Add(3);
            List<int> list = new List<int>();
            foreach (int i in array)
            {
                if (!list.Contains(i))
                {
                    list.Add(i);
                }
            }
            return list;
        }
      

  7.   


                List<string> list = new List<string>();
                list.Add("aa");
                list.Add("bb");
                list.Add("bb");
                list.Add("cc1");
                list.Add("bb");
                list.Add("cc1");
                for (int i = 0; i < list.Count;)
                {
                    if (list.LastIndexOf(list[i]) == i)
                    {
                        i++;
                    }
                    else
                    {
                        list.RemoveAt(i);
                    }
                }
      

  8.   

    public   static   void   Distinct(string   arg)   
      {   
      string[]   nums   =   arg.Split(',');   
      if(nums.Length   ==   0)   return;   
      ArrayList   result   =   new   ArrayList();   
      for(int   i   =   0;   i   <   nums.Length;   i++)   
      {   
      if(result.Contains(Convert.ToInt32(nums[i])))continue;   
      result.Add(Convert.ToInt32(nums[i]));//执行转换是为了实现数字排序   
      }   
      result.Sort();   
      for(int   i   =   0;   i   <   result.Count;   i++)//结果   
      {   
      Console.WriteLine(result[i].ToString());   
      }   
      }   
        
      Test:   
      Distinct("1,1,1,2,2,3,4,5,6,6,7");   
      Distinct("1,1,1,1,15,1,1,5,2,6,3");   
      Distinct("10,9,8,7,6,4,0,0,0,1,2");
      

  9.   

    都说了是2.0
    各位朋友为什么还是不看标题呢
    整个linq上来。
      

  10.   


    static void remove(List<string> strlist)
            {
                List<string> rs = new List<string>();
                List<int> index = new List<int>();
                int len = strlist.Count;
                for (int i = 0; i < len - 1; i++)
                {
                    int j = i + 1;
                    while (j < len)
                    {
                        if (strlist[i] == strlist[j])
                        {
                            index.Add(j);
                            strlist.RemoveAt(j);
                            len = len - 1;
                        }
                        j++;
                    }
                }   
            }
      

  11.   

    重发下:
    static void remove(List<string> strlist)
            {
                List<string> rs = new List<string>();
                int len = strlist.Count;
                for (int i = 0; i < len - 1; i++)
                {
                    int j = i + 1;
                    while (j < len)
                    {
                        if (strlist[i] == strlist[j])
                        {
                            strlist.RemoveAt(j);
                            len = len - 1;
                        }
                        j++;
                    }
                }   
            }
      

  12.   

    我晕,在去掉这个吧“List<string> rs = new List<string>();“
      

  13.   


      List<string> list = new List<string>();
      var c = (from li in list
      select li).Distinct();
      

  14.   

     不知道这对楼主有没有用:string[] str = new string[] { "abc", "ab", "abc", "ad" };            List<string> list = new List<string>();            foreach (string s in str)
                {
                    if (!list.Contains(s))
                    {
                        list.Add(s);
                    }
                }            string[] str2 = list.ToArray();            Console.WriteLine(String.Join(", ", str2));输出结果:abc,ab,ad