Avoid duplicates

前端 未结 2 1913
再見小時候
再見小時候 2021-01-27 11:45

how can i avoid duplicates from a string (in c#) eg.i have a,a,b,b,c i want to get the answer like a,b,c

相关标签:
2条回答
  • 2021-01-27 12:02

    By using HashSet<string>.

    0 讨论(0)
  • 2021-01-27 12:20

    You could use a List<> and the Contains method to check for this.

    Declare it as

    List<string> list = new List<string>();
    

    and check as

    if (!list.Contains(stringValue))
       list.Add(stringValue);
    
    0 讨论(0)
提交回复
热议问题