...

/

Solution Review: Implement the Rectangle Class

Solution Review: Implement the Rectangle Class

This review provides a detailed analysis to solve the 'Implement the Rectangle Class using the Concepts of Encapsulation' challenge.

We'll cover the following...

Solution

Press + to interact
C#
// Class Rectangle
class Rectangle {
// Private Fields
private int _length;
private int _width;
// Parameterized Constructor
public Rectangle(int length, int width) {
this._length = length;
this._width = width;
}
// Method to calculate Area of a rectangle
public int GetArea() {
return this._length * this._width;
}
}
class Program {
public static void Main(){
Rectangle obj = new Rectangle(2,2);
System.Console.WriteLine(obj.GetArea());
}
}

Explanation

The solution is straightforward.

...