Avoid duplicates

北城以北 提交于 2019-12-20 05:54:48

问题


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


回答1:


By using HashSet<string>.




回答2:


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);


来源:https://stackoverflow.com/questions/2264469/avoid-duplicates

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!