C#程序无法正常工作,空白控制台输出

时间:2016-03-20 06:26:41

标签: c# compiler-errors console-application

以下是控制台为空的程序 -

using System;
namespace here
{
    class Program
    {
        static void Main(string[] args)
        {
            double width, height, woodLength, glassArea;
            string widthString, heightString;
            widthString = Console.ReadLine();
            width = double.Parse(widthString);
            heightString = Console.ReadLine();
            height = double.Parse(heightString);
            woodLength = 2 * ( width + height ) * 3.25 ;
            glassArea = 2 * ( width * height ) ;
            Console.WriteLine ( "The length of the wood is " + woodLength + " feet" ) ;
            Console.WriteLine( "The area of the glass is " + glassArea + " square metres" ) ;
            Console.ReadKey(true);
        }
    }
}

这是显示输出的程序 -

using System;

namespace here
{
    class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.ReadKey(true);
        }
    }
}

我甚至尝试卸载我的所有防病毒软件,正如我在其他帖子中所读到的那样。什么都没有改变。

4 个答案:

答案 0 :(得分:1)

您的程序正在执行。 控制台是空白的,因为您没有在提示的开头打印任何内容。 试试这个

    using System;
    namespace here {
    class Program
    {
        static void Main(string[] args)
        {
            double width, height, woodLength, glassArea;
            string widthString, heightString;
            Console.WriteLine ("Enter width");
            widthString = Console.ReadLine();
            width = double.Parse(widthString);
            Console.WriteLine ("Enter height");

            heightString = Console.ReadLine();
            height = double.Parse(heightString);
            woodLength = 2 * ( width + height ) * 3.25 ;
            glassArea = 2 * ( width * height ) ;
            Console.WriteLine ( "The length of the wood is " +
                woodLength + " feet" ) ;
            Console.WriteLine( "The area of the glass is " +
                glassArea + " square metres" ) ;
            Console.ReadKey(true);
        }
    }
}

看看这里的输出: Output to the code snippet above in the answer post

答案 1 :(得分:0)

widthString = Console.ReadLine();等待,直到键盘输入内容并按下Enter键。

为程序输入两个值(宽度和高度,用空格分隔),然后按Enter键显示输出。

(我假设你是C#编程的新手 - 希望这有帮助!)

答案 2 :(得分:0)

正如Aniruddha Varma所说,你正在使用Console.ReadLine()。这等待您输入控制台。如果输入两个数字,则应打印该程序。程序暂停,等到你输入内容然后按回车键。然后第二个Readline函数执行相同的操作。输入两个值后,函数的其余部分将按预期继续。例如,我把:

    2
    4
    The length of the wood is 39 feet
    The area of the glass is 16 square meters

答案 3 :(得分:0)

您的程序可能正常工作,它只是在等待输入。试试这个:

static void Main(string[] args)
{
    Console.WriteLine("Starting program...");   
    double width, height, woodLength, glassArea;
    string widthString, heightString;

    Console.WriteLine("Enter width: ");
    widthString = Console.ReadLine();
    width = double.Parse(widthString);

    Console.WriteLine("Enter height: ");
    heightString = Console.ReadLine();
    height = double.Parse(heightString);

    Console.WriteLine("Calculating...")
    woodLength = 2 * ( width + height ) * 3.25 ;
    glassArea = 2 * ( width * height ) ;
    Console.WriteLine ( "The length of the wood is " + woodLength + " feet" ) ;
    Console.WriteLine( "The area of the glass is " + glassArea + " square metres" ) ;
    Console.ReadKey();
}