Hello! Great tip!
What do you think about this extension method:
public static class StringExtension
public unsafe static long LineCount(this string s)
long lineCount = 1;
fixed (char* pchar = s)
char* p = pchar;
for (; *p != '\0'; p++)
if (*p == '\n') lineCount++;
The class must be compiled into assembly with '/unsafe' option (simply mark "Allow unsafe code" checkbox on "Build" page of properties of project for this assembly).
long l = "hello\nmy friend\nGood luck".LineCount();
Please try to test it.