c# - 无法在 VS2019 C# 上更改 Console.Title

标签 c# console-application

刚开始使用 C#,我尝试做一些非常简单的事情,其中​​之一是更改控制台标题

我正在按照这些说明进行操作:Console.Title Property

上面的链接来自 Microsoft 文档,当我将它复制到我的程序中时,它可以正常工作!

当我尝试做同样的事情时,甚至更简单......好吧,标题根本没有改变。


我的代码:

using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "Hello World Program";
        }
    }
}

我的输出:

enter image description here

我做错了什么?我必须采取一些我不知道的额外步骤?


感谢您的宝贵时间和帮助。

最佳答案

程序退出后,控制台将不再具有您设置的标题。在程序结束前使用断点查看标题是什么。

Console.Title = "New";
return; // Set a breakpoint here.

或者您可以简单地添加“按任意键继续”(根据 MS 文档)

Console.WriteLine("Note that the new console title is \"{0}\"\n" +
                      "  (Press any key to quit.)", Console.Title);
Console.ReadKey(true);

关于c# - 无法在 VS2019 C# 上更改 Console.Title,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62418252/

相关文章:

c# - Cast 接口(interface)和类对象

c# - 如何从控制台应用程序访问 Application 对象?

ios - 在 Swift 中接受整数输入

c# - 为什么 AppDomain.CurrentDomain.BaseDirectory 的目标是控制台应用程序中的 bincatelog?

c++ - C++中的鼠标点击位置

c# - 使用 Activator.CreateInstance 创建的对象

c# - WIX 自动生成 GUID *?

c# - 在 Visual Studio 中编译为独立的可执行文件 (.exe)

c# - 通用与非通用重载调用

c# - ClickOnce 无法运行 - 获取 'Specified Cast Not Valid'