Compare char in List C# -


i wonder if there c# functions checks if letter exists more once? in word, send string function parameter check whether letter exist more once or not. example string "aabdck" should return "a". there way use dictionary??

is there way use dictionary??

yes loop through each character in string , track number of occurrences of each character in dictionary<char, int>.

dictionary<char, int> counts = new dictionary<char, int>(); foreach (var ch in mystring) {     if (counts.containskey(ch))     {         counts[ch]++;     }     else counts.add(ch, 1); }  

check dictionary keys value > 1.

you can linq. i'm not in front of compiler, like

list<char> multipletimes = mystring     .groupby(c => c)     .select(g => new { character = g.key, count = g.count() })     .where(a => a.count > 1)     .select(a => a.character)     .tolist(); 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -