RavenJeGames
RavenJeGames

Reputation: 153

Can't change Console.Title on VS2019 C#

Just starting with C# and I'm trying to do very simple things, one of these is changing the console title.

I'm following these instructions: Console.Title Property

The link above is from the Microsoft documentation, and when I copy it in my program it works!

When I try to do the same thing, even simpler... well the title doesn't change at all.


My code:

using System;

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

My output:

enter image description here

What am I doing wrong? There is some extra step that I must take which I'm not aware of?


Thank you for your time and help.

Upvotes: 6

Views: 3340

Answers (1)

Jawad
Jawad

Reputation: 11364

After your program exits, Console will no longer have the title you set it to. Use a breakpoint at the end to see what the title is before your program exits.

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

or you can simply add a 'press any key to continue' (as per the MS docs)

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

Upvotes: 6

Related Questions