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

List<T>().Add problem C# -

Javascript natural sort array/object and maintain index association -