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

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

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -