Skip to content

Instantly share code, notes, and snippets.

@tafo
Last active August 2, 2020 09:31
Show Gist options
  • Save tafo/c8a675374ea8488dfcbb1a7a297a236a to your computer and use it in GitHub Desktop.
Save tafo/c8a675374ea8488dfcbb1a7a297a236a to your computer and use it in GitHub Desktop.
public bool DetectCapitalUse(string word)
{
if (word.Length == 1) return true;
Func<char, bool> condition;
if (word[0] <= 'Z' && word[1] <= 'Z')
condition = c => c <= 'Z';
else
condition = c => c >= 'a';
for (var i = 1; i < word.Length; i++)
{
if (condition(word[i])) continue;
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment