Number of lines in code

Viewed 14589

Is there a tool or something else to count the number of lines in a specific C# project? Just out of curiosity...

4 Answers

I believe there are tools, but I find it easier to just use the Find in Files option and use this regex:

^~(:Wh@//.+)~(:Wh@\{:Wh@)~(:Wh@\}:Wh@)~(:Wh@/#).+

That regex is from here, which also shows how to search for it. It will return a number of matching lines (i.e. the number of lines in your code)

I've had good success with David Wheeler's SLOCCount. It's a command line tool, which will require Cygwin unfortunately, but I found it handled very large Java projects without fuss. C# is listed as a supported language for counting. Configuration is minimal, IIRC I just pointed it at a directory and it summarised all the type of code and broke it down in lines per language.

Highly recommended.

Related