Removing duplicates from a list collection

后端 未结 4 2019
天命终不由人
天命终不由人 2021-01-21 02:37

Hope someone can help me. I am using c# and I am somewhat new to it. I am loading a text file into my app and splitting the data on \",\" I am reading part of string into a

4条回答
  •  半阙折子戏
    2021-01-21 03:21

    A simple/dirty example follows:

    public List RemoveDuplicates(List listWithDups)
    {
       cleanList = new List();
       foreach (string s in listWithDups)
       {
          if (!cleanList.Contains(s))
             cleanList.Add(s);
       }
       return cleanList;
    }
    

    As a warning: String.Split on very large strings can cause consume huge amounts of memory and cause exceptions.

提交回复
热议问题