# UniqueKey Methods

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

## CompareTo(UniqueKey?) {#compareto-orleans-runtime-uniquekey-nullable-bfac9b13}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.uniquekey/methods/compareto-orleans-runtime-uniquekey-nullable-bfac9b13/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/Legacy/UniqueKey.cs#L208-L217)

```csharp
public int CompareTo(UniqueKey? other)
```

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

### Parameters

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

### Returns

A value that indicates the relative order of the objects being compared. The return value has these meanings: 

| Value | Meaning |
| --- | --- |
| Less than zero | This instance precedes `other` in the sort order. |
| Zero | This instance occurs in the same position in the sort order as `other`. |
| Greater than zero | This instance follows `other` in the sort order. |

## Equals(UniqueKey?) {#equals-orleans-runtime-uniquekey-nullable-86d29829}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.uniquekey/methods/equals-orleans-runtime-uniquekey-nullable-86d29829/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/Legacy/UniqueKey.cs#L197-L201)

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

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

### Parameters

- `other` (`UniqueKey?`): 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-4d79ddd3}

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

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/Legacy/UniqueKey.cs#L191)

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

Determines whether the specified object is equal to the current object.

### Parameters

- `o` (`object?`): The object to compare with the current object.

### Returns

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

## GetHashCode {#gethashcode-050bfe03}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.uniquekey/methods/gethashcode-050bfe03/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/Legacy/UniqueKey.cs#L222)

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

Serves as the default hash function.

### Returns

A hash code for the current object.

## NewGrainServiceKey(short, long) {#newgrainservicekey-short-long-debfd003}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.uniquekey/methods/newgrainservicekey-short-long-debfd003/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/Legacy/UniqueKey.cs)

```csharp
public static UniqueKey NewGrainServiceKey(short key, long typeData)
```

### Parameters

- `key` (`short`)
- `typeData` (`long`)

## NewGrainServiceKey(string, long) {#newgrainservicekey-string-long-0742c73e}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.uniquekey/methods/newgrainservicekey-string-long-0742c73e/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/Legacy/UniqueKey.cs)

```csharp
public static UniqueKey NewGrainServiceKey(string key, long typeData)
```

### Parameters

- `key` (`string`)
- `typeData` (`long`)

## NewKey {#newkey-8fd2ed76}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.uniquekey/methods/newkey-8fd2ed76/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/Legacy/UniqueKey.cs#L95)

```csharp
public static UniqueKey NewKey()
```

## NewSystemTargetKey(Guid, long) {#newsystemtargetkey-system-guid-long-14d7edda}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.uniquekey/methods/newsystemtargetkey-system-guid-long-14d7edda/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/Legacy/UniqueKey.cs#L112)

```csharp
public static UniqueKey NewSystemTargetKey(Guid guid, long typeData)
```

### Parameters

- `guid` (`Guid`)
- `typeData` (`long`)

## NewSystemTargetKey(short) {#newsystemtargetkey-short-51d28408}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.uniquekey/methods/newsystemtargetkey-short-51d28408/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/Legacy/UniqueKey.cs#L115)

```csharp
public static UniqueKey NewSystemTargetKey(short systemId)
```

### Parameters

- `systemId` (`short`)

## PrimaryKeyToGuid {#primarykeytoguid-09117d29}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.uniquekey/methods/primarykeytoguid-09117d29/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/Legacy/UniqueKey.cs#L187-L188)

```csharp
public Guid PrimaryKeyToGuid()
```

## PrimaryKeyToGuid(string?) {#primarykeytoguid-out-string-nullable-078f390f}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.uniquekey/methods/primarykeytoguid-out-string-nullable-078f390f/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/Legacy/UniqueKey.cs#L181-L182)

```csharp
public Guid PrimaryKeyToGuid(out string? extendedKey)
```

### Parameters

- `extendedKey` (`string?`)

## PrimaryKeyToLong {#primarykeytolong-72b1548f}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.uniquekey/methods/primarykeytolong-72b1548f/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/Legacy/UniqueKey.cs#L174-L176)

```csharp
public long PrimaryKeyToLong()
```

## PrimaryKeyToLong(string?) {#primarykeytolong-out-string-nullable-6016c551}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.uniquekey/methods/primarykeytolong-out-string-nullable-6016c551/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/Legacy/UniqueKey.cs#L166-L169)

```csharp
public long PrimaryKeyToLong(out string? extendedKey)
```

### Parameters

- `extendedKey` (`string?`)

## ToString {#tostring-4413642c}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.uniquekey/methods/tostring-4413642c/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/Legacy/UniqueKey.cs#L312)

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

Returns a string that represents the current object.

### Returns

A string that represents the current object.
