Calculate AreaofSquare
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace Lecture60
{
public class Program
{
public static void Main()
{
Square[] myArray = new Square[10];
for (int i = 0; i < myArray.Length; i++)
{
myArray[i] = new Square(i + 1);
Console.WriteLine("Length = {0}\nArea = {1}\n ", myArray[i].Length, myArray[i].Area);
}
}
}
public class Square
{
//Fields
private int length;
private int area;
//Constructor
public Square(int Length)
{
this.length = Length;
this.area = CalculateArea(Length);
}
//Method
private int CalculateArea(int length)
{
int area = length * length;
return area;
}
//Get set methods
public int Length
{
get { return length; }
}
public int Area
{
get { return area; }
}
}
}
Comments
Post a Comment