Skip to content

Instantly share code, notes, and snippets.

@tafo
Created August 2, 2020 08:35
Show Gist options
  • Save tafo/5526b8483c96d7643c6d876fd9a6dc1b to your computer and use it in GitHub Desktop.
Save tafo/5526b8483c96d7643c6d876fd9a6dc1b to your computer and use it in GitHub Desktop.
public bool DetectCapitalUse(string word)
{
var capitals = 0;
for (var i = 0; i < word.Length; i++)
{
if (char.IsUpper(word[i])) capitals++;
}
if (capitals == word.Length || capitals == 0) return true;
return capitals == 1 && char.IsUpper(word[0]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment