public class AlphabetGroupComparer : GroupEqualityComparer<string>
{
public override bool Equals(string x, string y)
{
if (x.Substring(0, 1).ToLower() == y.Substring(0, 1).ToLower())
return true;
return false;
}
public override string GroupName(string value)
{
if (value.Length == 0)
return string.Empty;
return value.Substring(0, 1).ToUpper();
}
}
public class DateGroupComparer : GroupEqualityComparer<DateTime>
{
string[] _groups = new string[] { "1901 - 1950", "1951 - 2000" };
public override bool Equals(DateTime x, DateTime y)
{
if (x.Year < 1951 && y.Year < 1951 || x.Year > 1950 && y.Year > 1950)
return true;
return false;
}
public override string GroupName(DateTime value)
{
if (value.Year < 1951)
return this._groups[0];
return this._groups[1];
}
}