Find Repeated Characters on string with LINQ, C#

string x = "AABCDEF"; List<char> repeatedCharacters = new List<char>(); var groupsOfChars = x.GroupBy(oChar => oChar); groupsOfChars.ToList().ForEach(item => { if (item.Count() > 1) repeatedCharacters.Add(item.Key); );

2 Responses

Thanks a lot for the solution.

string x = "AABCDEEF";
List<char> repeatedCharacters = new List<char>();
var groupsOfChars = x.GroupBy(oChar => oChar);
groupsOfChars.ToList().ForEach(item =>
{
if (item.Count() > 1) repeatedCharacters.Add(item.Key);
}
);
repeatedCharacters.ForEach(Console.WriteLine);
Thanks a lot for the solution.

string x = "AABCDEEF";
List<char> repeatedCharacters = new List<char>();
var groupsOfChars = x.GroupBy(oChar => oChar);
groupsOfChars.ToList().ForEach(item =>
{
if (item.Count() > 1) repeatedCharacters.Add(item.Key);
}
);
repeatedCharacters.ForEach(Console.WriteLine);

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.