Here LINQ is used for the trivial (whitespace) word count:
string s = "My name is ABC XYZ";
int l = s.Length;
int w = s.Count(x => x == ' ') + 1;
This will usually work better than a call Split(), because it treats the string as an enumerated stream of characters and just takes it into account, rather than creating an array of strings to store words.
source
share