, , ints whos ASCII :
private static bool StartsWithRange(string value, char first, char last)
{
if (string.IsNullOrEmpty(value))
{
return false;
}
if (first > last)
{
throw new ArgumentException(string.Format("'{0}' shouldn't come after '{1}'.", first, last), nameof(last));
}
int intValue = value.ToLower()[0];
return intValue >= first && intValue <= last;
}
:
Students.Where(s => StartsWithRange(s, 'a', 'e')).ToList();
, , :
Assert.IsFalse(StartsWithRange("abcd", 'd', 'e'));
Assert.IsTrue(StartsWithRange("dcd", 'd', 'e'));
Assert.IsTrue(StartsWithRange("Dcd", 'd', 'e'));
Assert.IsTrue(StartsWithRange("ebcd", 'd', 'e'));
Assert.IsTrue(StartsWithRange("Ebcd", 'd', 'e'));
Assert.IsFalse(StartsWithRange("fbcd", 'd', 'e'));
Assert.IsFalse(StartsWithRange("Fbcd", 'd', 'e'));
Assert.IsFalse(StartsWithRange(string.Empty, 'd', 'e'));
ToLower
-call, , value
.
, , "" , , .