Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Parent : IComparable<Parent>
- class Child : Parent
- Child a = new Child();
- Child b = new Child();
- a.CompareTo(b);
- List<Child> l = new List<Child>();
- l.Add(b);
- l.Add(a);
- l.Sort();
- public int CompareTo(IDType other)
- {
- return this.Name.ToString().CompareTo(other.ToString());
- }
- public class Parent : IComparable<Parent>
- {
- public int Age { get; set; }
- public int CompareTo(Parent other)
- {
- return this.Age.CompareTo(other.Age);
- }
- }
- public class Child : Parent
- {
- public string Name { get; set; }
- }
- public class Parent : IComparable
- {
- public int Age { get; set; }
- public int CompareTo(object other)
- {
- Parent p = other as Parent;
- return this.Age.CompareTo(p.Age);
- }
- }
- public class Child : Parent
- {
- public string Name { get; set; }
- }
- List<Child> c = new List<Child>();
- c.Add(new Child { Age = 10, Name = "Alex" });
- c.Add(new Child { Age = 6, Name = "Jack" });
- c.Add(new Child { Age = 15, Name = "Bob" });
- c.Sort();
Add Comment
Please, Sign In to add comment