Employee Class

The following code includes the complete listing of the Employee class, including the overridden methods of the System.Object class. This reviews many of the topics already mentioned in this chapter:

using System; using System.Collections; namespace Donis.CSharpBook { public class Starter { public static void Main() { Employee obj1 = new Employee(5678); Employee obj2 = new Employee(5678); if (obj1 == obj2) { Console.WriteLine("equals"); } else { Console.WriteLine("not equals"); } } } class Employee { public Employee(int id) { if ((id < 1000) || (id > 9999)) { throw new Exception( "Invalid Employee ID"); } propID = id; } public static bool operator==(Employee obj1, Employee obj2) { return obj1.Equals(obj2); } public static bool operator!=(Employee ...

Get Programming Microsoft® Visual C#® 2008: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.