OperatingSystem Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Representerar information om ett operativsystem, till exempel version och plattformsidentifierare. Det går inte att ärva den här klassen.
public ref class OperatingSystem sealed : ICloneable
public ref class OperatingSystem sealed : ICloneable, System::Runtime::Serialization::ISerializable
[System.Serializable]
public sealed class OperatingSystem : ICloneable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class OperatingSystem : ICloneable, System.Runtime.Serialization.ISerializable
public sealed class OperatingSystem : ICloneable, System.Runtime.Serialization.ISerializable
[<System.Serializable>]
type OperatingSystem = class
interface ICloneable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type OperatingSystem = class
interface ICloneable
interface ISerializable
type OperatingSystem = class
interface ICloneable
interface ISerializable
Public NotInheritable Class OperatingSystem
Implements ICloneable
Public NotInheritable Class OperatingSystem
Implements ICloneable, ISerializable
- Arv
-
OperatingSystem
- Attribut
- Implementeringar
Exempel
I följande kodexempel används OperatingSystem objektet för att visa information om körningsoperativsystemet.
using System;
public class Example
{
public static void Main()
{
var os = Environment.OSVersion;
Console.WriteLine("Current OS Information:\n");
Console.WriteLine("Platform: {0:G}", os.Platform);
Console.WriteLine("Version String: {0}", os.VersionString);
Console.WriteLine("Version Information:");
Console.WriteLine(" Major: {0}", os.Version.Major);
Console.WriteLine(" Minor: {0}", os.Version.Minor);
Console.WriteLine("Service Pack: '{0}'", os.ServicePack);
}
}
// If run on a Windows 8.1 system, the example displays output like the following:
// Current OS Information:
//
// Platform: Win32NT
// Version String: Microsoft Windows NT 6.2.9200.0
// Version Information:
// Major: 6
// Minor: 2
// Service Pack: ''
// If run on a Windows 7 system, the example displays output like the following:
// Current OS Information:
//
// Platform: Win32NT
// Version String: Microsoft Windows NT 6.1.7601 Service Pack 1
// Version Information:
// Major: 6
// Minor: 1
// Service Pack: 'Service Pack 1'
open System
let os = Environment.OSVersion
printfn "Current OS Information:\n"
printfn $"Platform: {os.Platform:G}"
printfn $"Version String: {os.VersionString}"
printfn $"Version Information:"
printfn $" Major: {os.Version.Major}"
printfn $" Minor: {os.Version.Minor}"
printfn $"Service Pack: '{os.ServicePack}'"
// If run on a Windows 8.1 system, the example displays output like the following:
// Current OS Information:
//
// Platform: Win32NT
// Version String: Microsoft Windows NT 6.2.9200.0
// Version Information:
// Major: 6
// Minor: 2
// Service Pack: ''
// If run on a Windows 7 system, the example displays output like the following:
// Current OS Information:
//
// Platform: Win32NT
// Version String: Microsoft Windows NT 6.1.7601 Service Pack 1
// Version Information:
// Major: 6
// Minor: 1
// Service Pack: 'Service Pack 1'
Module Example
Public Sub Main()
Dim os As OperatingSystem = Environment.OSVersion
Console.WriteLine("Current OS Information:")
Console.WriteLine()
Console.WriteLine("Platform: {0:G}", os.Platform)
Console.WriteLine("Version String: {0}", os.VersionString)
Console.WriteLine("Version Information:")
Console.WriteLine(" Major: {0}", os.Version.Major)
Console.WriteLine(" Minor: {0}", os.Version.Minor)
Console.WriteLine("Service Pack: '{0}'", os.ServicePack)
End Sub
End Module
' If run on a Windows 8.1 system, the example displays output like the following:
' Current OS Information:
'
' Platform: Win32NT
' Version String: Microsoft Windows NT 6.2.9200.0
' Version Information:
' Major: 6
' Minor: 2
' Service Pack: ''
' If run on a Windows 7 system, the example displays output like the following:
' Current OS Information:
'
' Platform: Win32NT
' Version String: Microsoft Windows NT 6.1.7601 Service Pack 1
' Version Information:
' Major: 6
' Minor: 1
' Service Pack: 'Service Pack 1'
Kommentarer
Klassen OperatingSystem innehåller information om ett operativsystem.
Om du vill ha information om det aktuella körningsoperativsystemet hämtar du objektet OperatingSystem som returneras av Environment.OSVersion egenskapen. En lista över Windows operativsystemversioner och deras motsvarande versionsnummer som returneras av metoden Version och VersionString och metoden ToString finns i Operating System Version.
Klassen är avsiktligt OperatingSystem inte ett generellt syfte med att beskriva ett operativsystem, och du kan inte härleda en mer inkluderande typ från OperatingSystem klassen. Om du behöver en typ för att innehålla annan information om ett operativsystem skapar du en egen typ och tar sedan med ett fält av typen OperatingSystem och eventuella ytterligare fält, egenskaper eller metoder som du behöver.
Konstruktorer
| Name | Description |
|---|---|
| OperatingSystem(PlatformID, Version) |
Initierar en ny instans av OperatingSystem klassen med det angivna plattformsidentifierarvärdet och versionsobjektet. |
Egenskaper
| Name | Description |
|---|---|
| Platform |
Hämtar ett PlatformID uppräkningsvärde som identifierar operativsystemplattformen. |
| ServicePack |
Hämtar service pack-versionen som representeras av det här OperatingSystem objektet. |
| Version |
Hämtar ett Version objekt som identifierar operativsystemet. |
| VersionString |
Hämtar den sammanfogade strängrepresentationen av plattformsidentifieraren, versionen och service pack som för närvarande är installerade på operativsystemet. |
Metoder
| Name | Description |
|---|---|
| Clone() |
Skapar ett OperatingSystem objekt som är identiskt med den här instansen. |
| Equals(Object) |
Avgör om det angivna objektet är lika med det aktuella objektet. (Ärvd från Object) |
| GetHashCode() |
Fungerar som standard-hash-funktion. (Ärvd från Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Fyller i ett SerializationInfo objekt med de data som krävs för att deserialisera den här instansen. |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| ToString() |
Konverterar värdet för det här OperatingSystem objektet till motsvarande strängrepresentation. |