You are employed as a developer at ABC.com. You make use of C# and ASP.NET for
development purposes.
You are instructed to develop a new Rectangle class. The new class should allow for Rectangle
objects to be compared.
What option suitably represents the necessary code?
A.
class Rectangle : IConvertible
{
public double Length { get; set; }
public double Width { get; set; }
public double GetArea()
{
return Length * Width;
}
public intCompareTo(object obj)
{
Rectangle target = (Rectangle)obj;
double diff = this.GetArea() – target.GetArea();
if (diff == 0)
return 0;
else if (diff > 0)
return 1;
else return -1;
}
}
B.
class Rectangle : IComparable
{
public Length { get; set; }
public Width { get; set; }
public GetArea()
{
return Area;
}
public intCompareTo(object obj)
{
Rectangle target = (Rectangle)obj;
double diff = this.GetArea() – target.GetArea();
if (diff == 0)
return 0;
else if (diff > 0)
return 1;
else return -1;
}
}
C.
class Rectangle : IComparable
{
private double Length { get; set; }
private double Width { get; set; }
private double GetArea()
{
return Length * Width;
}
private intCompareTo(object obj)
{
Rectangle target = (Rectangle)obj;
double diff = this.GetArea() – target.GetArea();
if (diff == 0)
return 0;
else if (diff > 0)
return 1;
else return -1;
}
}
D.
class Rectangle : IComparable
{
private Length { get; set; }
private Width { get; set; }
private GetArea()
{
return Area;
}
private intCompareTo(object obj)
{
Rectangle target = (Rectangle)obj;
double diff = this.GetArea() – target.GetArea();
if (diff == 0)
return 0;
else if (diff > 0)
return 1;
else return -1;
}
}
Answer C is incorrect! IConvertible? WTF?
C is the correct answer.
The correct answer is B because CompareTo method cannot be more restrictive than method defined on interface.
The correct answer is A. Its not necessary implement interface IComparable.
C: Due to private access modifiers caused not able assign value the properties.