public static void Run(string[] args) { TaxPayer[] taxArray = new TaxPayer[5]; for (int x = 0; x < taxArray.Length; x++) { Console.WriteLine("Enter gross income for customer NO.{0}", x + 1); taxArray[x] = new TaxPayer(int.Parse(Console.ReadLine())); } Console.WriteLine("\n---------------------------------------------"); Console.WriteLine("Details:\n"); foreach (TaxPayer person in taxArray) { Console.WriteLine("GrossIncome: {0}", person.YearlyGrossIncome); Console.WriteLine("Tax owed: {0}\n", person.TaxOwed); } //Sort based on tax owed Array.Sort(taxArray); Console.WriteLine("\n---------------------------------------------"); Console.WriteLine("Sorted list: Lowest tax to highest tax."); foreach (TaxPayer person in taxArray) { Console.WriteLine("GrossIncome: {0}", person.YearlyGrossIncome); Console.WriteLine("Tax owed: {0}\n", person.TaxOwed); } }
int IComparable.CompareTo(object obj) { int returnVal; TaxPayer temp = (TaxPayer)obj; if (this.taxOwed > temp.taxOwed) { returnVal = 1; } else if (this.taxOwed < temp.taxOwed) { returnVal = -1; } else { returnVal = 0; } return(returnVal); }