static void Main(string[] args) { Person p1 = new Person("Nasko", 25); Person p2 = new Person("Asi", 26); int older = p1.CompareTo(p2); Console.WriteLine(older); PersonAgeComparator ageComparator = new PersonAgeComparator(); int compareAges = ageComparator.Compare(p1, p2); Console.WriteLine(compareAges); PersonNameComparator nameComparator = new PersonNameComparator(); int compareNames = nameComparator.Compare(p1, p2); Console.WriteLine(compareNames); }
static void Main(string[] args) { var nameComparer = new PersonNameComparator(); var ageComparer = new PersonAgeComparator(); var peopleByName = new SortedSet <Person>(nameComparer); var peopleByAge = new SortedSet <Person>(ageComparer); int peopleNumber = int.Parse(Console.ReadLine()); for (int i = 0; i < peopleNumber; i++) { string[] personData = Console.ReadLine().Split(); string name = personData[0]; int age = int.Parse(personData[1]); peopleByName.Add(new Person(name, age)); peopleByAge.Add(new Person(name, age)); } PrintSet(peopleByName); PrintSet(peopleByAge); }