无法更改Console.Title,VS2019 C#

问题描述 投票:0回答:1

仅从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

我在做什么错?还有一些我不知道的额外步骤吗?


感谢您的时间和帮助。

c# console-application
1个回答
0
投票

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

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);

0
投票

尝试使用:

using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "Hello World Program";
            #if DEBUG
                Console.Title = "Hello World Program";
            #endif
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.