Using StreamReader to count duplicates?
问题 I'm using streamreader now to read a file of people names, it is a text file, of people first names, so there are obviously duplicates, and i want to be able to display how many people have the same now so for example: josh alex josh john alex I want it to say, josh 2 alex 2 john 1 but I can't seem to find an easy way of doing this, what would be the easiest way about doing this, 回答1: I'd say use a Dictionary<string, int> . Dictionary<string, int> firstNames = new Dictionary<string, int>();