C# not outputting to console

2019-08-27 21:01发布

I'm sure there's some simple answer, but none of the other Stack Overflow posts has helped me. My code will not log to the Console, and it's hard to do anything useful with that state of affairs.

using System;
using System.Diagnostics;

namespace Learning
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Debug.Log ("this?");
            Debug.Print ("How about this?");
            Console.WriteLine ("WORK");
            Console.ReadLine ();
        }
    }
}

I've been able to write to the console before, I don't know why it's being persnickety now.

2条回答
该账号已被封号
2楼-- · 2019-08-27 21:02

You may want to check what kind of application you are using. For example, if you are making a Forms Application, you won't have access to the Console functions.

You can change this by going into the Solution Properties, and changing it from a Windows Forms Application to a Console Application. This won't have any effect on your program, other than it will run a Console alongside.

enter image description here

enter image description here

查看更多
虎瘦雄心在
3楼-- · 2019-08-27 21:29

Probably because your code doesn't actually compile. Log() is a static method of Debugger, not Debug, and it takes three arguments: level, category, and message.

public static void Main (string[] args)
{
    System.Diagnostics.Debugger.Log(1, "category", "this?");
    System.Diagnostics.Debug.Print ("How about this?");
    Console.WriteLine ("WORK");
    Console.ReadLine ();
}

It's worth noting that Debug/Debugger methods will not do you any good unless you are Debugging. To start a debugging session in mono, go to the Run -> Debug

查看更多
登录 后发表回答