# GrainReference Methods

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainreference/)

## Cast {#cast-1-a6105e77}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainreference/methods/cast-1-a6105e77/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Runtime/GrainReference.cs#L327)

```csharp
public virtual TGrainInterface Cast<TGrainInterface>()
```

Creates a new grain reference which implements the specified grain interface.

### Returns

A new grain reference which implements the specified interface type.

## Equals(GrainReference?) {#equals-orleans-runtime-grainreference-nullable-987f72af}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainreference/methods/equals-orleans-runtime-grainreference-nullable-987f72af/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Runtime/GrainReference.cs#L341)

```csharp
public bool Equals(GrainReference? other)
```

Indicates whether the current object is equal to another object of the same type.

### Parameters

- `other` (`GrainReference?`): An object to compare with this object.

### Returns

`true` if the current object is equal to the `other` parameter; otherwise, `false`.

## Equals(object?) {#equals-object-nullable-d05cef41}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainreference/methods/equals-object-nullable-d05cef41/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Runtime/GrainReference.cs#L337)

```csharp
public override bool Equals(object? obj)
```

Tests this reference for equality to another object. Two grain references are equal if they both refer to the same grain.

### Parameters

- `obj` (`object?`): The object to test for equality against this reference.

### Returns

`true` if the object is equal to this reference.

## GetHashCode {#gethashcode-d299909b}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainreference/methods/gethashcode-d299909b/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Runtime/GrainReference.cs#L344)

```csharp
public override int GetHashCode()
```

Serves as the default hash function.

### Returns

A hash code for the current object.

## GetUniformHashCode {#getuniformhashcode-56eb0a38}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainreference/methods/getuniformhashcode-56eb0a38/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Runtime/GrainReference.cs#L355)

```csharp
public uint GetUniformHashCode()
```

Get a uniform hash code for this grain reference.

### Returns

The uniform hash code.

## ToString {#tostring-09f7a6d4}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainreference/methods/tostring-09f7a6d4/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Runtime/GrainReference.cs#L397)

```csharp
public sealed override string ToString()
```

Returns a string that represents the current object.

### Returns

A string that represents the current object.

## operator ==(GrainReference?, GrainReference?) {#op-equality-orleans-runtime-grainreference-nullable-orleans-runtime-grainreferen-eba5b632}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainreference/methods/op-equality-orleans-runtime-grainreference-nullable-orleans-runtime-grainreferen-eba5b632/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Runtime/GrainReference.cs#L367-L369)

```csharp
public static bool operator ==(GrainReference? reference1, GrainReference? reference2)
```

Compares two references for equality. Two grain references are equal if they both refer to the same grain.

### Parameters

- `reference1` (`GrainReference?`): First grain reference to compare.
- `reference2` (`GrainReference?`): Second grain reference to compare.

### Returns

`true` if both grain references refer to the same grain (by grain identifier).

## operator !=(GrainReference?, GrainReference?) {#op-inequality-orleans-runtime-grainreference-nullable-orleans-runtime-grainrefer-d47e528e}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainreference/methods/op-inequality-orleans-runtime-grainreference-nullable-orleans-runtime-grainrefer-d47e528e/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Runtime/GrainReference.cs#L381-L383)

```csharp
public static bool operator !=(GrainReference? reference1, GrainReference? reference2)
```

Compares two references for inequality. Two grain references are equal if they both refer to the same grain.

### Parameters

- `reference1` (`GrainReference?`): First grain reference to compare.
- `reference2` (`GrainReference?`): Second grain reference to compare.

### Returns

`false` if both grain references are resolved to the same grain (by grain identifier).
