Прочитать на английском

Поделиться через


OperatingSystem.ToString Метод

Определение

Преобразует значение этого объекта OperatingSystem в эквивалентное ему строковое представление.

public override string ToString();

Возвращаемое значение

Строковое представление значений, возвращаемых свойствами Platform, Version и ServicePack.

Примеры

В следующем примере кода показано использование ToString метода для отображения OperatingSystem объектов .

// Example for the OperatingSystem constructor and the
// OperatingSystem.ToString( ) method.
using System;

class OpSysConstructDemo
{
    // Create and display an OperatingSystem object.
    static void BuildOSObj( PlatformID pID, Version ver )
    {
        OperatingSystem os = new OperatingSystem( pID, ver );

        Console.WriteLine( "   {0}", os.ToString( ) );
    }

    static void BuildOperatingSystemObjects( )
    {
        // The Version object does not need to correspond to an
        // actual OS version.
        Version verNull     = new Version( );
        Version verMajMin   = new Version( 3, 11 );
        Version verMMBld    = new Version( 5, 25, 625 );
        Version verMMBVer   = new Version( 5, 6, 7, 8 );
        Version verString   = new Version( "3.5.8.13" );

        // All PlatformID members are shown here.
        BuildOSObj( PlatformID.Win32NT, verNull );
        BuildOSObj( PlatformID.Win32S, verMajMin );
        BuildOSObj( PlatformID.Win32Windows, verMMBld );
        BuildOSObj( PlatformID.WinCE, verMMBVer );
        BuildOSObj( PlatformID.Win32NT, verString );
    }

    public static void Main( )
    {
        Console.WriteLine(
            "This example of the OperatingSystem constructor " +
            "and \nOperatingSystem.ToString( ) " +
            "generates the following output.\n" );
        Console.WriteLine(
            "Create and display several different " +
            "OperatingSystem objects:\n" );

        BuildOperatingSystemObjects( );

        Console.WriteLine(
            "\nThe OS version of the host computer is:\n\n   {0}",
            Environment.OSVersion.ToString( ) );
    }
}

/*
This example of the OperatingSystem constructor and
OperatingSystem.ToString( ) generates the following output.

Create and display several different OperatingSystem objects:

   Microsoft Windows NT 0.0
   Microsoft Win32S 3.11
   Microsoft Windows 98 5.25.625
   Microsoft Windows CE 5.6.7.8
   Microsoft Windows NT 3.5.8.13

The OS version of the host computer is:

   Microsoft Windows NT 5.1.2600.0
*/

Комментарии

Список версий операционной системы Windows и соответствующие номера версий см. в разделе Версия операционной системы.

Применяется к

Продукт Версии
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 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, 4.8.1
.NET Standard 2.0, 2.1

См. также раздел