OperatingSystem Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Représente des informations sur un système d’exploitation, comme la version et l’identificateur de plateforme. Cette classe ne peut pas être héritée.
public ref class OperatingSystem sealed : ICloneable, System::Runtime::Serialization::ISerializable
public ref class OperatingSystem sealed : ICloneable
public sealed class OperatingSystem : 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
type OperatingSystem = class
interface ICloneable
interface ISerializable
[<System.Serializable>]
type OperatingSystem = class
interface ICloneable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type OperatingSystem = class
interface ICloneable
interface ISerializable
Public NotInheritable Class OperatingSystem
Implements ICloneable, ISerializable
Public NotInheritable Class OperatingSystem
Implements ICloneable
- Héritage
-
OperatingSystem
- Attributs
- Implémente
Exemples
L’exemple de code suivant utilise l’objet OperatingSystem pour afficher des informations sur le système d’exploitation runtime.
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'
Remarques
La OperatingSystem classe contient des informations sur un système d’exploitation.
Pour plus d’informations sur le système d’exploitation runtime actuel, récupérez l’objet OperatingSystem retourné par la Environment.OSVersion propriété. Pour obtenir la liste des versions du système d’exploitation Windows et leurs numéros de version correspondants retournés par les Version propriétés et VersionString la méthode, consultez Version du ToStringsystème d’exploitation.
Par conception, la OperatingSystem classe n’est pas un moyen universel de décrire un système d’exploitation et vous ne pouvez pas dériver un type plus inclusif de la OperatingSystem classe. Si vous avez besoin d’un type pour contenir d’autres informations sur un système d’exploitation, créez votre propre type, puis incluez un champ de type OperatingSystem et tous les champs, propriétés ou méthodes supplémentaires dont vous avez besoin.
Constructeurs
| Nom | Description |
|---|---|
| OperatingSystem(PlatformID, Version) |
Initialise une nouvelle instance de la OperatingSystem classe à l’aide de la valeur d’identificateur de plateforme et de l’objet de version spécifiés. |
Propriétés
| Nom | Description |
|---|---|
| Platform |
Obtient une PlatformID valeur d’énumération qui identifie la plateforme du système d’exploitation. |
| ServicePack |
Obtient la version du Service Pack représentée par cet OperatingSystem objet. |
| Version |
Obtient un Version objet qui identifie le système d’exploitation. |
| VersionString |
Obtient la représentation sous forme de chaîne concaténée de l’identificateur de plateforme, de la version et du Service Pack actuellement installés sur le système d’exploitation. |
Méthodes
| Nom | Description |
|---|---|
| Clone() |
Crée un OperatingSystem objet identique à cette instance. |
| Equals(Object) |
Détermine si l’objet spécifié est égal à l’objet actuel. (Hérité de Object) |
| GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Obsolète.
Remplit un SerializationInfo objet avec les données nécessaires pour désérialiser cette instance. |
| GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
| IsAndroid() |
Indique si l’application actuelle est en cours d’exécution sur Android. |
| IsAndroidVersionAtLeast(Int32, Int32, Int32, Int32) |
Vérifie si la version Android (retournée par la commande |
| IsBrowser() |
Indique si l’application actuelle s’exécute en tant que WASM dans un navigateur. |
| IsFreeBSD() |
Indique si l’application actuelle est en cours d’exécution sur FreeBSD. |
| IsFreeBSDVersionAtLeast(Int32, Int32, Int32, Int32) |
Vérifie si la version FreeBSD (retournée par la commande |
| IsIOS() |
Indique si l’application actuelle s’exécute sur iOS ou MacCatalyst. |
| IsIOSVersionAtLeast(Int32, Int32, Int32) |
Vérifie si la version iOS/MacCatalyst (retournée par |
| IsLinux() |
Indique si l’application actuelle est en cours d’exécution sur Linux. |
| IsMacCatalyst() |
Indique si l’application actuelle est en cours d’exécution sur Mac Catalyst. |
| IsMacCatalystVersionAtLeast(Int32, Int32, Int32) |
Recherchez la version de Mac Catalyst (version iOS présentée dans la documentation Apple) avec une comparaison de versions ≤. Utilisé pour protéger les API qui ont été ajoutées dans la version de Mac Catalyst donnée. |
| IsMacOS() |
Indique si l’application actuelle s’exécute sur macOS. |
| IsMacOSVersionAtLeast(Int32, Int32, Int32) |
Vérifie si la version macOS (retournée par |
| IsOSPlatform(String) |
Indique si l’application actuelle est en cours d’exécution sur la plateforme spécifiée. |
| IsOSPlatformVersionAtLeast(String, Int32, Int32, Int32, Int32) |
Vérifie si la version du système d’exploitation est supérieure ou égale à la version de plateforme spécifiée. Cette méthode peut être utilisée pour protéger les API qui ont été ajoutées dans la version de système d’exploitation spécifiée. |
| IsTvOS() |
Indique si l’application actuelle est en cours d’exécution sur tvOS. |
| IsTvOSVersionAtLeast(Int32, Int32, Int32) |
Vérifie si la version tvOS (retournée par |
| IsWasi() |
Indique si l’application actuelle s’exécute en tant que WASI. |
| IsWatchOS() |
Indique si l’application actuelle est en cours d’exécution sur watchOS. |
| IsWatchOSVersionAtLeast(Int32, Int32, Int32) |
Vérifie si la version watchOS (retournée par |
| IsWindows() |
Indique si l’application actuelle s’exécute sur Windows. |
| IsWindowsVersionAtLeast(Int32, Int32, Int32, Int32) |
Vérifie si la version windows (retournée par |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| ToString() |
Convertit la valeur de cet OperatingSystem objet en sa représentation sous forme de chaîne équivalente. |