简体   繁体   English

Console.WriteLine和调试器在Windows / VSC上不起作用?

[英]Console.WriteLine & Debugger not working on Windows/VSC?

I'm following a C#/.NET PluralSight tutorial (building a gradebook) and for some reason, my first 'Console.WriteLine(result)' isn't displaying anything when I use the "Start without Debugging" option. 我正在关注C#/。NET PluralSight教程(构建成绩簿),由于某种原因,当我使用“不调试开始”选项时,我的第一个“ Console.WriteLine(result)”没有显示任何内容。 The second Console.WriteLine works fine. 第二个Console.WriteLine工作正常。

Also, the debugger doesn't work; 另外,调试器无法正常工作。 I set a breakpoint and the debugger runs without stopping and finishes without any errors. 我设置了一个断点,调试器将不停止运行,并且完成时不会出现任何错误。 I'm working in Visual Studio code. 我正在使用Visual Studio代码。 Thoughts? 思考?

using System;

namespace GradeBook
{
    class Program
    {
        static void Main(string[] args) //this is a method
        {
            var numbers = new[] {12.7, 10.3, 6.11, 4.1};
            var result = 0.0;

            foreach(double number in numbers) {
                result += number;
            }
            Console.WriteLine(result);

            if(args.Length > 0) {
                Console.WriteLine($"Hello, {args[0]} !");
            } else {
                Console.WriteLine("Hello!");
            }
        }
    }
}

在您的主要方法的末尾放置Console.ReadKey();

I think you should put Console.ReadLine(); 我认为你应该把Console.ReadLine(); after the if-else statement. 在if-else语句之后。 There's other way too, but I used to code this line. 还有另一种方法,但是我曾经编写这行代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM