loading
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;

class MainClass {
  public static void Main (string[] args) {
    var personList = new List<Person>
    {
      new Person {Name="Fatih", Age=31 },
      new Person {Name ="Alice", Age=2 },
      new Person {Name="Mehmet", Age=30 },
      new Person {Name="Eric", Age = 28  },
      new Person {Name="Tarik", Age = 22  }
    };

    personList.Sort();

    foreach(Person person in personList)
    {
      Console.WriteLine($"{person.Name} {person.Age}");
    }
  }

  public class Person : IComparable<Person>, IComparable
  {
    public string Name { get; set; }
    public int Age { get; set; }

    public int CompareTo(Person other)
    {
      int result = Age.CompareTo(other.Age);

      if (result == 0)
      {
          result = Name.CompareTo(other.Name);
      }

      return result;
    }

    public int CompareTo(object obj)
    {
      Person temp = (Person)obj;

      return CompareTo(temp);
    }
  }
}