You can try using this code for counting the words,
int GetWords(string paragraph) {
return (
paragraph.Split(new string[] {" "},
StringSplitOptions.RemoveEmptyEntries).Length
);
}
This would return the total number of words in the paragraph or what so ever the string is. To test this program logic, you can use this fiddle:
https://dotnetfiddle.net/E1JIy2[
^]. For more on this Split method signature and other details, see
this MSDN document[
^].