简体   繁体   中英

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. The second Console.WriteLine works fine.

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. 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(); after the if-else statement. There's other way too, but I used to code this line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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