The source code below demonstrates how to count all of the lines of code that comprise a C#.NET program. This code applies to C# programs written using Visual Studio 2005, but can be easily adapted to other environments.
This code works by finding all of the source code (*.cs) files in your application's root folder and level-1 subfolders. A stream reader is then used to count the lines of code in each source code file.