Wednesday, February 25, 2009

Comapring Two Objects

When we comapre two integer value it is as easy as possible

private int Compare (int x, int y)
{
return x < y ? x : y;
}

When we comapre two Object value we usually performed boxing and unboxing which create overhead on the Application. We used a collection similarly when value is added to a collection boxing take places when value is retrieved unboxing take places. Collection makes a job easy for boxing and unboxing


private T Compare (T x, T y) where T : IComparable
{
if (x.CompareTo (y) < 0)
return x;
else
return y;
}