The following code checks if a string is a pangram or not:
public static class StringExtensions
{
public static IEnumerable<char> EnglishAlphabet
{
get
{
for (char i = 'a'; i <= 'z'; i++)
{
yield return i;
}
yield break;
}
}
/// <summary>
/// Check if the source string is a pangram.
/// </summary>
/// <remarks>
/// The default dictionary is the english one.
/// </remarks>
public static bool IsPangram(this string source)
{
return source.IsPangram(EnglishAlphabet);
}
/// <summary>
/// Check if the source string is a pangram.
/// </summary>
/// <remarks>
/// A pangram is a string that uses every letter in the alphabet.
/// </remarks>
public static bool IsPangram(this string source, IEnumerable<char> alphabet)
{
var lowerAlphabet = new string(alphabet.ToArray()).ToLower();
IDictionary<char, bool> alphabetCharacters = lowerAlphabet.ToDictionary(c => c, c => false);
var lowerSource = source.ToLower();
foreach(char character in lowerSource)
{
alphabetCharacters[character] = true;
}
return !alphabetCharacters.Values.Contains(false);
}
}
Do you see anything wrong/weird in it? Any feedback (style, naming, performance) is more than welcome.