All pastes #915813 Raw Edit

RickyWh

public text v1 · immutable
#915813 ·published 2008-02-24 02:13 UTC
rendered paste body
using System;
using System.Collections;
using System.Reflection;

namespace RickyTest
{
	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");
			}
			obj1.First = "Ricky";
			obj1.Last = "Mossip";
			Console.WriteLine(obj1.ToString());
		}
	}
	
	public 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 obj1, Employee obj2)
		{
			return !obj1.Equals(obj2);
		}
		
		public override bool Equals(object obj)
		{
			Employee _obj = obj as Employee;
			
			if(obj==null)
			{
				return false;
			}
			return this.GetHashCode()==_obj.GetHashCode();
		}
		
		public override int GetHashCode()
		{
			return EmplID;
		}
		
		public string FullName
		{
			get
			{
				return propFirst+" "+propLast;
			}
		}
		
		private string propFirst;
		public string First
		{
			get
			{
				return propFirst;
			}
			set
			{
				propFirst=value;
			}
		}
		
		private string propLast;
		public string Last
		{
			get
			{
				return propLast;
			}
			set
			{
				propLast=value;
			}
		}
		
		private readonly int propID;
		public int EmplID
		{
			get
			{
				return propID;
			}
		}
		
		public override string ToString()
		{
			return FullName;
		}
	}
}