Freigeben über


RuntimeHelpers.GetObjectValue-Methode

Schachtelt einen Werttyp.

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

Syntax

'Declaration
Public Shared Function GetObjectValue ( _
    obj As Object _
) As Object
'Usage
Dim obj As Object
Dim returnValue As Object

returnValue = RuntimeHelpers.GetObjectValue(obj)
public static Object GetObjectValue (
    Object obj
)
public:
static Object^ GetObjectValue (
    Object^ obj
)
public static Object GetObjectValue (
    Object obj
)
public static function GetObjectValue (
    obj : Object
) : Object

Parameter

  • obj
    Der zu schachtelnde Werttyp.

Rückgabewert

Gibt eine geschachtelte Kopie von obj zurück, wenn es sich um eine Wertklasse handelt, andernfalls wird obj selbst zurückgegeben.

Hinweise

Durch Schachteln eines Werttyps wird ein Objekt erstellt und eine flache Kopie der Felder des angegebenen Werttyps werden in das neue Objekt eingefügt.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie eine Wertklasse mit der GetObjectValue-Methode mittels Boxing konvertiert wird.

Imports System.Runtime.CompilerServices

' Declare a value type.
Structure Point2I

    Dim x As Integer
    Dim y As Integer
End Structure

Module Program

    Sub Main(ByVal args() As String)


        ' Allocate an unboxed Point2I (not on the heap).
        Dim pnt As Point2I
        pnt.x = 0
        pnt.y = 0

        ' Box the value.  (Put it in the heap.)
        Dim objPntr As Object = RuntimeHelpers.GetObjectValue(pnt)
    End Sub


End Module
using System;
using System.Runtime.CompilerServices;

// Declare a value type.
struct Point2I
{
    public int x;
    public int y;
}

class Program
{

    static void Main(string[] args)
    {
        // Allocate an unboxed Point2I (not on the heap).
        Point2I pnt;
        pnt.x = 0;
        pnt.y = 0;

        // Box the value.  (Put it in the heap.)
        object objPntr = RuntimeHelpers.GetObjectValue(pnt);

    }
}

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

RuntimeHelpers-Klasse
RuntimeHelpers-Member
System.Runtime.CompilerServices-Namespace