OperatingSystem::ToString Method ()


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Converts the value of this OperatingSystem object to its equivalent string representation.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

virtual String^ ToString() override

Return Value

Type: System::String^

The string representation of the values returned by the Platform, Version, and ServicePack properties.

See Operating System Version on the Windows Dev Center for a list of Windows operating system versions and their corresponding version numbers.

The following code example illustrates the use of the ToString method to display OperatingSystem objects.

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

// Create and display an OperatingSystem object.
void BuildOSObj( PlatformID pID, Version^ ver )
   OperatingSystem^ os = gcnew OperatingSystem( pID,ver );
   Console::WriteLine( "   {0}", os->ToString() );

void BuildOperatingSystemObjects()

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

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

int main()
   Console::WriteLine( "This example of the OperatingSystem constructor and \n"
   "OperatingSystem::ToString( ) generates the following "
   "output.\n" );
   Console::WriteLine( "Create and display several different "
   "OperatingSystem objects:\n" );
   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
   Microsoft Windows NT

The OS version of the host computer is:

   Microsoft Windows NT 5.1.2600.0

.NET Framework
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top