RuntimeHelpers.Equals(Object, Object) 方法

定義

判斷指定 Object 實例是否被視為相等。

public:
 static bool Equals(System::Object ^ o1, System::Object ^ o2);
public static bool Equals(object? o1, object? o2);
public static bool Equals(object o1, object o2);
static member Equals : obj * obj -> bool
Public Shared Function Equals (o1 As Object, o2 As Object) As Boolean

參數

o1
Object

第一個比較的對象。

o2
Object

第二個比較物件。

傳回

trueo1與 為同一實例o2,或兩者皆為 null,或兩者為相同值型態且底層記憶體值相等;否則,。 false

範例

以下範例示範如何利用該 Equals 方法比較兩個物體。

using System;
using System.Runtime.CompilerServices;

class Program
{

    static void Main(string[] args)
    {

        int x = 1; int y = 1;

        bool ret = RuntimeHelpers.Equals(x, y);

        Console.WriteLine("The return value of RuntimeHelpers.Equals is: " + ret);
    }
}
Imports System.Runtime.CompilerServices


Module Program

    Sub Main(ByVal args() As String)


        Dim x As Integer = 1
        Dim y As Integer = 1

        Dim ret As Boolean
        ret = RuntimeHelpers.Equals(x, y)

        Console.WriteLine("The return value of RuntimeHelpers.Equals is: " + ret)
    End Sub


End Module

備註

編譯程式會使用這個方法。

適用於

另請參閱