using System.Linq;
public static class Pangram
{
private const string Letters = "abcdefghijklmnopqrstuvwxyz";
public static bool IsPangram(string input)
{
var lowerCaseInput = input.ToLower();
return Letters.All(letter => lowerCaseInput.Contains(letter));
}
}
- This begins by lowercasing the input by using ToLower.
- It then checks if all letters in the alphabet are contained in the input,
using the LINQ method
All
with theString
methodContains
.
Instead of lowercasing the input, Contains
could take an optional StringComparison
argument,
but a case-insensitive comparison is about seven times slower than lowercasing the input and then doing an exact comparison.
11th Dec 2024
·
Found it useful?