0

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();
            }
        }
    }
}
2
  • The ReadLine method is designed to wait for you to press Enter. See the MSDN remarks for details Commented Feb 22, 2016 at 17:29
  • Looks like you got a few good answers, please accept one. Commented Feb 22, 2016 at 18:33

4 Answers 4

1

Console.ReadLine(); requiers the user to hit enter. That's the pause you're seeing

Sign up to request clarification or add additional context in comments.

2 Comments

I have tried removing it and still not doing what its supposed to
Where is it stopping (use the debugger to pause and see what line of code it's on when prompted for user input)
0

Remove Console.ReadLine(); from both methods of your Rectangles class and also from your foreach(which is in main) loop

Comments

0

remove Console.ReadLine(); from your for loop

1 Comment

Cheers forgot about the ones in the class file
0

Console.ReadLine() is the curlprit which is waiting for a key stroke after every line execution within the for loop.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.