ex-int-02-meet-the-teacher/MeetTheTeacher/Model/Comparison/ByRoomComparer.cs
2025-04-24 23:34:37 +02:00

26 lines
615 B
C#

namespace MeetTheTeacher.Model.Comparison;
/// <summary>
/// Compares <see cref="Teacher"/> instances by their room, sorting in ascending order
/// </summary>
/// <inheritdoc cref="IComparer{Teacher}"/>
public sealed class ByRoomComparer : IComparer<Teacher>
{
public int Compare(Teacher? x, Teacher? y)
{
if (x == null && y == null)
{
return 0;
}
if (x == null)
{
return 1;
}
if (y == null)
{
return -1;
}
return string.Compare(x!.Room, y!.Room, StringComparison.Ordinal);
}
}