Skip to content

Instantly share code, notes, and snippets.

@lgolubyev
Created June 16, 2022 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgolubyev/4ffb8567475dcfc874db19f752c858bb to your computer and use it in GitHub Desktop.
Save lgolubyev/4ffb8567475dcfc874db19f752c858bb to your computer and use it in GitHub Desktop.
public IEnumerable<string> CapitalizeFirstLetter(IEnumerable<string> enumerable)
{
if (!enumerable.Any())
{
throw new ArgumentException("The sequence is empty.");
}
return enumerable.Select(CapitalizeFirstLetterLocal);
static string CapitalizeFirstLetterLocal(string input) =>
input switch
{
null or "" => throw new ArgumentNullException(nameof(input)),
_ => string.Concat(input[0].ToString().ToUpper(), input.AsSpan(1))
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment