【发布时间】:2011-01-01 13:20:16
【问题描述】:
在 c# 中确定程序员是通过 IDE 运行程序还是通过其用户运行程序的最佳方法是什么?
【问题讨论】:
在 c# 中确定程序员是通过 IDE 运行程序还是通过其用户运行程序的最佳方法是什么?
【问题讨论】:
if (System.Diagnostics.Debugger.IsAttached) {
// You are debugging
}
【讨论】:
public static bool IsInVisualStudio
{
get
{
bool inIDE = false;
string[] args = System.Environment.GetCommandLineArgs();
if (args != null && args.Length > 0)
{
string prgName = args[0].ToUpper();
inIDE = prgName.EndsWith("VSHOST.EXE");
}
return inIDE;
}
}
【讨论】:
args 是字符串数组,不是字符串。