C# not outputting to console

江枫思渺然 提交于 2019-12-11 20:36:03

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/30609708/c-sharp-not-outputting-to-console

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!