Function Kata "LOC"

Develop a function that counts the lines of code (LOC) in a well-formed C# source code.

The source code is delivered as a string and the number of lines containing executable code is returned. Lines that only consist of comments or whitespace should therefore be filtered out [1].

Please note:

  • C# does not recognize nested comments
  • Comment characters - /*, */, // - do not open/close comments within strings
  • Strings in comments are not recognized as such, i.e. the comment
    /*a "*/"b... ends before "b.
  • Executable code can be in the same line as a comment: before /* // or after */.

Variation #1

Also return the number of lines that were filtered out as pure comment or pure whitespace.


[1] Character strings are counted as executable code. If they extend over several lines or even contain whitespace lines, these must also be counted.