[CSHARP]using System.Text.RegularExpressions;[/CSHARP]

[CSHARP]public static long LineCount2(string source, bool isFileName)
{
if (source != null)
{
string text = source;
long numOfLines = 0;
if (isFileName)
{
using (FileStream FS = new FileStream(source, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
using (StreamReader SR = new StreamReader(FS))
{
while (text != null)
{
text = SR.ReadLine();
if (text != null)
{
++numOfLines;
}
}
}
}
return (numOfLines);
}
else
{
Regex RE = new Regex("\n", RegexOptions.Multiline);
MatchCollection theMatches = RE.Matches(text);
return (theMatches.Count + 1);
}
}
else
{
// Handle a null source here.
return (0);
}
}[/CSHARP]