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
Allwith theStringmethodContains.
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.
4th Sep 2024
·
Found it useful?