# GrainId Methods

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

## CompareTo(GrainId) {#compareto-orleans-runtime-grainid-567abe8a}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/compareto-orleans-runtime-grainid-567abe8a/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/GrainId.cs#L172-L175)

```csharp
public int CompareTo(GrainId 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` (`GrainId`): 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. |

## Create(GrainType, IdSpan) {#create-orleans-runtime-graintype-orleans-runtime-idspan-afe6366e}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/create-orleans-runtime-graintype-orleans-runtime-idspan-afe6366e/)

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

```csharp
public static GrainId Create(GrainType type, IdSpan key)
```

Creates a new [GrainType](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.graintype/) instance.

### Parameters

- `type` (`GrainType`)
- `key` (`IdSpan`)

## Create(GrainType, string) {#create-orleans-runtime-graintype-string-4502adfe}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/create-orleans-runtime-graintype-string-4502adfe/)

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

```csharp
public static GrainId Create(GrainType type, string key)
```

Creates a new [GrainType](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.graintype/) instance.

### Parameters

- `type` (`GrainType`)
- `key` (`string`)

## Create(string, string) {#create-string-string-98188728}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/create-string-string-98188728/)

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

```csharp
public static GrainId Create(string type, string key)
```

Creates a new [GrainType](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.graintype/) instance.

### Parameters

- `type` (`string`)
- `key` (`string`)

## Equals(GrainId) {#equals-orleans-runtime-grainid-51eb7984}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/equals-orleans-runtime-grainid-51eb7984/)

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

```csharp
public bool Equals(GrainId other)
```

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

### Parameters

- `other` (`GrainId`): 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-d657dd7f}

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

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

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

Indicates whether this instance and a specified object are equal.

### Parameters

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

### Returns

`true` if `obj` and this instance are the same type and represent the same value; otherwise, `false`.

## GetHashCode {#gethashcode-399e8d73}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/gethashcode-399e8d73/)

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

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

Returns the hash code for this instance.

### Returns

A 32-bit signed integer that is the hash code for this instance.

## GetObjectData(SerializationInfo, StreamingContext) {#getobjectdata-system-runtime-serialization-serializationinfo-system-runtime-seri-80a153de}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/getobjectdata-system-runtime-serialization-serializationinfo-system-runtime-seri-80a153de/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/GrainId.cs#L163-L167)

```csharp
public void GetObjectData(SerializationInfo info, StreamingContext context)
```

Populates a `System.Runtime.Serialization.SerializationInfo` with the data needed to serialize the target object.

### Parameters

- `info` (`SerializationInfo`): The `System.Runtime.Serialization.SerializationInfo` to populate with data.
- `context` (`StreamingContext`): The destination (see `System.Runtime.Serialization.StreamingContext`) for this serialization.

### Exceptions

- `System.Security.SecurityException`: The caller does not have the required permission.

## GetUniformHashCode {#getuniformhashcode-ce5b2bb6}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/getuniformhashcode-ce5b2bb6/)

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

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

Generates a uniform, stable hash code for a grain id.

## Parse(ReadOnlySpan&lt;char&gt;, IFormatProvider?) {#parse-system-readonlyspan-char-system-iformatprovider-nullable-7a320ddc}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/parse-system-readonlyspan-char-system-iformatprovider-nullable-7a320ddc/)

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

```csharp
public static GrainId Parse(ReadOnlySpan<char> value, IFormatProvider? provider = null)
```

Parses a [GrainId](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/) from the span.

### Parameters

- `value` (`ReadOnlySpan<char>`)
- `provider` (`IFormatProvider?`)

## Parse(string) {#parse-string-600e1018}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/parse-string-600e1018/)

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

```csharp
public static GrainId Parse(string value)
```

Parses a [GrainId](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/) from the string.

### Parameters

- `value` (`string`)

## Parse(string, IFormatProvider?) {#parse-string-system-iformatprovider-nullable-c2a785ff}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/parse-string-system-iformatprovider-nullable-c2a785ff/)

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

```csharp
public static GrainId Parse(string value, IFormatProvider? provider = null)
```

Parses a [GrainId](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/) from the string.

### Parameters

- `value` (`string`)
- `provider` (`IFormatProvider?`)

## ToString {#tostring-858cc18c}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/tostring-858cc18c/)

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

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

Returns the fully qualified type name of this instance.

### Returns

The fully qualified type name.

## TryParse(ReadOnlySpan&lt;char&gt;, IFormatProvider?, GrainId) {#tryparse-system-readonlyspan-char-system-iformatprovider-nullable-out-orleans-ru-e61c0b58}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/tryparse-system-readonlyspan-char-system-iformatprovider-nullable-out-orleans-ru-e61c0b58/)

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

```csharp
public static bool TryParse(ReadOnlySpan<char> value, IFormatProvider? provider, out GrainId result)
```

Tries to parse a [GrainId](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/) from the span.

### Parameters

- `value` (`ReadOnlySpan<char>`)
- `provider` (`IFormatProvider?`)
- `result` (`GrainId`)

### Returns

`true` if a valid [GrainId](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/) was parsed. `false` otherwise

## TryParse(string?, IFormatProvider?, GrainId) {#tryparse-string-nullable-system-iformatprovider-nullable-out-orleans-runtime-gra-17dca7b2}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/tryparse-string-nullable-system-iformatprovider-nullable-out-orleans-runtime-gra-17dca7b2/)

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

```csharp
public static bool TryParse(string? value, IFormatProvider? provider, out GrainId result)
```

Tries to parse a [GrainId](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/) from the string.

### Parameters

- `value` (`string?`)
- `provider` (`IFormatProvider?`)
- `result` (`GrainId`)

### Returns

`true` if a valid [GrainId](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/) was parsed. `false` otherwise

## TryParse(string?, GrainId) {#tryparse-string-nullable-out-orleans-runtime-grainid-494c5605}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/tryparse-string-nullable-out-orleans-runtime-grainid-494c5605/)

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

```csharp
public static bool TryParse(string? value, out GrainId result)
```

Tries to parse a [GrainId](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/) from the string.

### Parameters

- `value` (`string?`)
- `result` (`GrainId`)

### Returns

`true` if a valid [GrainId](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/) was parsed. `false` otherwise

## operator ==(GrainId, GrainId) {#op-equality-orleans-runtime-grainid-orleans-runtime-grainid-8e7f8b20}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/op-equality-orleans-runtime-grainid-orleans-runtime-grainid-8e7f8b20/)

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

```csharp
public static bool operator ==(GrainId left, GrainId right)
```

Compares the provided operands for equality.

### Parameters

- `left` (`GrainId`): The left operand.
- `right` (`GrainId`): The right operand.

### Returns

`true` if the provided values are equal, otherwise `false`.

## operator !=(GrainId, GrainId) {#op-inequality-orleans-runtime-grainid-orleans-runtime-grainid-5ea95eb4}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/methods/op-inequality-orleans-runtime-grainid-orleans-runtime-grainid-5ea95eb4/)

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

```csharp
public static bool operator !=(GrainId left, GrainId right)
```

Compares the provided operands for inequality.

### Parameters

- `left` (`GrainId`): The left operand.
- `right` (`GrainId`): The right operand.

### Returns

`true` if the provided values are not equal, otherwise `false`.
