System.OperatingSystem.Clone 方法

方法描述

创建与此实例相同的 OperatingSystem 对象。

语法定义(C# System.OperatingSystem.Clone 方法 的用法)

public Object Clone()

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
返回值 System.Object OperatingSystem 对象,是此实例的副本。

提示和注释

System.OperatingSystem.Clone 方法例子

复本与原始对象进行比较,以显示它们不是同一个对象。

// Example for the OperatingSystem.Clone method.
using System;

class CloneCompareDemo
{
    // Copy, clone, and duplicate an OperatingSystem object.
    static void CopyOperatingSystemObjects( )
    {
        // The Version object does not need to correspond to an 
        // actual OS version.
        Version verMMBVer = new Version( 5, 6, 7, 8 );

        OperatingSystem opCreate1 = new 
            OperatingSystem( PlatformID.Win32NT, verMMBVer );

        // Create another OperatingSystem object with the same 
        // parameters as opCreate1.
        OperatingSystem opCreate2 = new 
            OperatingSystem( PlatformID.Win32NT, verMMBVer );

        // Clone opCreate1 and copy the opCreate1 reference.
        OperatingSystem opClone = 
            (OperatingSystem)opCreate1.Clone( );
        OperatingSystem opCopy = opCreate1;

        // Compare the various objects for equality.
        Console.WriteLine( "{0,-50}{1}", 
            "Is the second object the same as the original?", 
            opCreate1.Equals( opCreate2 ) );
        Console.WriteLine( "{0,-50}{1}", 
            "Is the object clone the same as the original?", 
            opCreate1.Equals( opClone ) );
        Console.WriteLine( "{0,-50}{1}", 
            "Is the copied object the same as the original?", 
            opCreate1.Equals( opCopy ) );
    } 

    static void Main( )
    {
        Console.WriteLine(
            "This example of OperatingSystem.Clone( ) " +
            "generates the following output.\n" );
        Console.WriteLine(
            "Create an OperatingSystem object, and then " +
            "create another object with the \n" +
            "same parameters. Clone and copy the original " +
            "object, and then compare \n" +
            "each object with the original " +
            "using the Equals( ) method. Equals( ) \n" +
            "returns true only when both " +
            "references refer to the same object.\n" );

        CopyOperatingSystemObjects( );
    } 
} 

/*
This example of OperatingSystem.Clone( ) generates the following output.

Create an OperatingSystem object, and then create another object with the
same parameters. Clone and copy the original object, and then compare
each object with the original using the Equals( ) method. Equals( )
returns true only when both references refer to the same object.

Is the second object the same as the original?    False
Is the object clone the same as the original?     False
Is the copied object the same as the original?    True
*/

异常

异常 异常描述

命名空间

namespace: System

程序集: mscorlib(在 mscorlib.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0、1.1、1.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。