// First example of classes using System; using System.Collections.Generic; namespace ConsoleApp6 { class Program { public class Human { protected string first; protected string last; protected uint age; public string First { get { return first; } set { first = value; } } public string Last { get { return last; } set { last = value; } } public uint Age { get { return age; } set { age = value; } } public Human() { first = last = ""; age = 0; } public Human(string _first, string _last, uint _age) { first = _first; last = _last; age = _age; } public override string ToString() { return String.Format("{0}, {1} is {2} years old.", Last, First, Age); //return "First = " + first } } public class Student : Human, IComparable { private string zid; public string Zid { get { return zid; } set { if (value[0] != 'z' && value[0] != 'Z') return; if (value.Length > 8 || value.Length < 7) // zDDDDDD or zDDDDDDD return; // So we have a leading Z character, and the correct number of characters for (int i = 1; i < value.Length; i++) if (!Char.IsDigit(value[i])) return; zid = value; } } public string Nonsense => Zid + " is a student"; public Student() : base() { zid = ""; } public Student(string _first, string _last, uint _age, string _zid) : base(_first, _last, _age) { Zid = _zid; } public int CompareTo(Object alpha) { if (alpha == null) throw new ArgumentNullException(); // otherwise Student rightOp = alpha as Student; // Typcasing with English! if (rightOp != null) // The typecast was success return this.Zid.CompareTo(rightOp.Zid); else throw new ArgumentException(); } public override string ToString() { return String.Format("{0} and is an NIU student, ID == {1}.", base.ToString(), Zid); } } static void Main(string[] args) { Human myself = new Human("Rogness", "Daniel", 35); Console.WriteLine(myself.ToString()); Student alsoMyself = new Student("Rogness", "Daniel", 35, "z174735"); Student myAlias = new Student("Strauss", "Viktor", 36, "z1560953"); Student myOtherAlias = new Student("Zimmerman", "Philip", 20, "z0123456"); Console.WriteLine(alsoMyself.ToString() + "\n\n"); SortedSet pool; pool = new SortedSet(); pool.Add(alsoMyself); pool.Add(myAlias); pool.Add(myOtherAlias); foreach (Student i in pool) { Console.WriteLine(i); } } } }