using System;
namespace Test
{
public class Program
{
private static void Main(string[] args)
{
int Number = 10;
Console.WriteLine(Number.ToString());
Customer C1 = new Customer();
}
}
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
//override - select ToString using intellisense
public override string ToString()
{
return this.LastName + ", " + this.FirstName;
}
}
}
============================
using System;
namespace Test
{
public class Program
{
private static void Main(string[] args)
{
int i = 10;
int j = 10;
Console.WriteLine(i == j);
Console.WriteLine(i.Equals(j));
Console.WriteLine();
Direction direction1 = Direction.East;
Direction direction2 = Direction.West;
Console.WriteLine(direction1 == direction2);
Console.WriteLine(direction1.Equals(direction2));
Console.WriteLine();
Customer C1 = new Customer();
C1.FirstName = "Simon";
C1.LastName = "Tan";
Customer C2 = C1;
Console.WriteLine(C1 == C2);
Console.WriteLine(C1.Equals(C2));
Console.WriteLine();
Customer C3 = new Customer();
C3.FirstName = "Simon";
C3.LastName = "Tan";
Console.WriteLine(C1 == C3);
Console.WriteLine(C1.Equals(C3));
}
}
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
//override - click Equals using intellisense
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
if(!(obj is Customer))
{
return false;
}
return this.FirstName == ((Customer)obj).FirstName &&
this.LastName == ((Customer)obj).LastName;
}
public override int GetHashCode()
{
return this.FirstName.GetHashCode() & this.LastName.GetHashCode();
}
}
public enum Direction
{
East = 1,
West,
North,
South
}
}