Afficher en anglais

Partage via


Console.Title Propriété

Définition

Obtient ou définit le titre à afficher dans la barre de titre de la console.

C#
public static string Title { [System.Runtime.Versioning.SupportedOSPlatform("windows")] get; [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] set; }
C#
public static string Title { [System.Runtime.Versioning.SupportedOSPlatform("windows")] get; [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] [System.Runtime.Versioning.UnsupportedOSPlatform("android")] [System.Runtime.Versioning.UnsupportedOSPlatform("ios")] [System.Runtime.Versioning.UnsupportedOSPlatform("tvos")] set; }
C#
public static string Title { get; set; }

Valeur de propriété

String

Chaîne à afficher dans la barre de titre de la console. La longueur maximale de la chaîne de titre est limitée à 24 500 caractères.

Attributs

Exceptions

Dans une opération get, le titre récupéré est plus long que 24 500 caractères.

Dans une opération set, le titre spécifié est plus long que 24 500 caractères.

Dans une opération set, le titre spécifié est null.

Une erreur d'E/S s'est produite.

L’opération Get est invoquée sur un système d’exploitation autre que Windows.

Exemples

Cet exemple illustre la Title propriété. L’exemple affiche le titre actuel de la fenêtre du système d’exploitation, attend une pression sur une touche, puis affiche un nouveau titre.

C#
// This example demonstrates the Console.Title property.
using System;

class Sample
{
    public static void Main()
    {
    Console.WriteLine("The current console title is: \"{0}\"",
                      Console.Title);
    Console.WriteLine("  (Press any key to change the console title.)");
    Console.ReadKey(true);
    Console.Title = "The title has changed!";
    Console.WriteLine("Note that the new console title is \"{0}\"\n" +
                      "  (Press any key to quit.)", Console.Title);
    Console.ReadKey(true);
    }
}
/*
This example produces the following results:

>myTitle
The current console title is: "Command Prompt - myTitle"
  (Press any key to change the console title.)
Note that the new console title is "The title has changed!"
  (Press any key to quit.)

*/

S’applique à

Produit Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1