using System.Runtime.InteropServices;
[DllImport("kernel32.dll")] public static extern Boolean AllocConsole(); [DllImport("kernel32.dll")] public static extern Boolean FreeConsole();
//输出信息之前,先AllocConsole() ,用完后 FreeConsole()
/// <summary> /// 控制台输出内容 /// </summary> /// <param name="output">输入文本</param> /// <param name="color">输出颜色</param> public static void WriteLine(string output,ConsoleColor color) { Console.ForegroundColor = color; Console.WriteLine(@"[{0}] {1}", DateTime.Now, output); }