I have to generate randomly letters in a string
this.text = "";
Random rndChar = new Random();
for (int i = 0; i < 50; i++)
{
this.text = this.text + (char)rndChar.Next(65,91);
}
The result is something about GUHZBVUTSUZHBF...
Now i have to generate a list of the characters in ascending order with the number of times each character has been repeated. I tried it with
SortedList letters = new SortedList();
for(int i = 0; i < 50; i++)
{
letters.Add(this.text[i], i);
}
foreach (Char entry in letters.Values)
Console.WriteLine(entry);
, but that doesn't work:
"System.ArgumentException: 'Item has already been added. Key in dictionary: 'J' Key being added: 'J'' ."
What does that mean? How can i solve that issue?