How to detect internally whether the application is in console or windows mode in C#

余生长醉 提交于 2019-12-23 17:42:31

问题


Is there a way to check whether a program is in console or windows mode from within the application itself? I know that Read and ReadLine can somehow detect this, but how?


回答1:


You should be able to check to see if Console.In == StreamReader.Null;

If this is true, there is no console attached. For example, the following works properly for this:

public static bool IsConsoleApplication
{
    get { return Console.In != StreamReader.Null; }
}


来源:https://stackoverflow.com/questions/10957440/how-to-detect-internally-whether-the-application-is-in-console-or-windows-mode-i

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