I have another class called Rectangles and I am iterating over the objects to add them into the list with a for loop. After that I am using a foreach loop to print all the data out at once. For some reason I am having to press enter each time to display the result. This is my class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rectangle
{
public class Rectangles
{
int Length;
int Width;
// constructor
public void CalcPerimiter(int Length, int Width)
{
int Perimiter = Length + Width;
Console.WriteLine("The perimiter is " + Perimiter);
Console.ReadLine();
}
public void CalcArea(int Length, int Width)
{
int Area = Length * Width;
Console.WriteLine("The Area is " + Area);
Console.ReadLine();
}
}
}
This is my main
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rectangle;
using System.Collections;
namespace Rectangle_calculation
{
class Program
{
static void Main(string[] args)
{
Rectangle.Rectangles[] First = new Rectangles[20];//Storing th
for (int i = 0; i < First.Length; i++)
{
First[i] = new Rectangles();
First[i].CalcPerimiter(33, 45);
First[i].CalcArea(22, 88);
First[i].CalcPerimiter(23, 75);
First[i].CalcArea(12, 55);
First[i].CalcPerimiter(32, 25);
First[i].CalcArea(220, 88);
First[i].CalcPerimiter(239, 35);
First[i].CalcArea(120, 15);
}
foreach (Rectangles rectangle in First)
{
Console.WriteLine(rectangle.ToString());
Console.ReadLine();
}
}
}
}