Count file lines in C# -


i want know how many lines have in file. how can in simple way (i mean, not go through on over file , count each line)? there command that?

well:

int lines = file.readalllines(path).length; 

is simple, not efficient huge text files. i'd use textreader in cases, avoid excessive buffering:

int lines = 0; using (textreader reader = file.opentext(path)) {     while (reader.readline() != null) { lines++; } } 

Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -