RuntimeHelpers.Equals(Object, Object) Method

Definition

Determines whether the specified Object instances are considered equal.

C#
public static bool Equals(object? o1, object? o2);
C#
public static bool Equals(object o1, object o2);

Parameters

o1
Object

The first object to compare.

o2
Object

The second object to compare.

Returns

true if o1 is the same instance as o2, or if both are null, or if both are the same value type and the values of their underlying memory are equal; otherwise, false.

Examples

The following example demonstrates how to compare two objects by using the Equals method.

C#
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);
    }
}

Remarks

This method is used by compilers.

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also