I have got over 600k lines of string. I want to group same strings and learn their counts.
So example
i go to school
i like music
i like games
i like music
i like music
i like games
i like music
So result will be
i go to school , 1
i like games , 2
i like music , 4
How can I do that with the fastest possible way?
The
GroupBy
method is what you want. You'll need your strings to be in a list or something that implementsIEnumerable<string>
. TheFile.ReadLines
suggested by spender will return anIEnumerable<string>
that reads the file line by line.If you want them in order of least to most (as in your example) just add an
OrderBy