Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count number of individual lines from a txt file c#

I have a txt document which has over 14000 different lines many of these are duplicates, is it possible to count the number of unique entries?

like image 215
Evildommer5 Avatar asked Dec 17 '22 07:12

Evildommer5


1 Answers

You can use the File.ReadLines Method and LINQ's Distinct and Count Extension Methods:

var result = File.ReadLines("input.txt").Distinct().Count();
like image 67
dtb Avatar answered Dec 28 '22 08:12

dtb