# GrainIdKeyExtensions Methods

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

## CreateGuidKey(Guid) {#createguidkey-system-guid-7ac224ad}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainidkeyextensions/methods/createguidkey-system-guid-7ac224ad/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/GrainIdKeyExtensions.cs#L101-L104)

```csharp
public static IdSpan CreateGuidKey(Guid key)
```

Creates an [IdSpan](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/) representing a `System.Guid` key.

### Parameters

- `key` (`Guid`): The key.

### Returns

An [IdSpan](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/) representing the provided key.

## CreateGuidKey(Guid, ReadOnlySpan&lt;byte&gt;) {#createguidkey-system-guid-system-readonlyspan-byte-e8b68c47}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainidkeyextensions/methods/createguidkey-system-guid-system-readonlyspan-byte-e8b68c47/)

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

```csharp
public static IdSpan CreateGuidKey(Guid key, ReadOnlySpan<byte> keyExtension)
```

Creates an [IdSpan](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/) representing a `System.Guid` key and key extension string.

### Parameters

- `key` (`Guid`): The key.
- `keyExtension` (`ReadOnlySpan<byte>`): The UTF-8 encoded key extension.

### Returns

An [IdSpan](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/) representing the provided key and key extension.

## CreateGuidKey(Guid, string?) {#createguidkey-system-guid-string-nullable-64b124df}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainidkeyextensions/methods/createguidkey-system-guid-string-nullable-64b124df/)

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

```csharp
public static IdSpan CreateGuidKey(Guid key, string? keyExtension)
```

Creates an [IdSpan](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/) representing a `System.Guid` key and key extension string.

### Parameters

- `key` (`Guid`): The key.
- `keyExtension` (`string?`): The key extension.

### Returns

An [IdSpan](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/) representing the provided key and key extension.

## CreateIntegerKey(long) {#createintegerkey-long-16175bd9}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainidkeyextensions/methods/createintegerkey-long-16175bd9/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/GrainIdKeyExtensions.cs#L24-L27)

```csharp
public static IdSpan CreateIntegerKey(long key)
```

Creates an [IdSpan](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/) representing a `System.Int64` key.

### Parameters

- `key` (`long`): The key.

### Returns

An [IdSpan](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/) representing the provided key.

## CreateIntegerKey(long, ReadOnlySpan&lt;byte&gt;) {#createintegerkey-long-system-readonlyspan-byte-2d6e88eb}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainidkeyextensions/methods/createintegerkey-long-system-readonlyspan-byte-2d6e88eb/)

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

```csharp
public static IdSpan CreateIntegerKey(long key, ReadOnlySpan<byte> keyExtension)
```

Creates an [IdSpan](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/) representing a `System.Int64` key and key extension string.

### Parameters

- `key` (`long`): The key.
- `keyExtension` (`ReadOnlySpan<byte>`): The UTF-8 encoded key extension.

### Returns

An [IdSpan](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/) representing the provided key and key extension.

## CreateIntegerKey(long, string?) {#createintegerkey-long-string-nullable-4bdb6b9b}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainidkeyextensions/methods/createintegerkey-long-string-nullable-4bdb6b9b/)

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

```csharp
public static IdSpan CreateIntegerKey(long key, string? keyExtension)
```

Creates an [IdSpan](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/) representing a `System.Int64` key and key extension string.

### Parameters

- `key` (`long`): The key.
- `keyExtension` (`string?`): The key extension.

### Returns

An [IdSpan](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/) representing the provided key and key extension.

## GetGuidKey(GrainId) {#getguidkey-this-orleans-runtime-grainid-d82bb22f}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainidkeyextensions/methods/getguidkey-this-orleans-runtime-grainid-d82bb22f/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/GrainIdKeyExtensions.cs#L325-L330)

```csharp
public static Guid GetGuidKey(this GrainId grainId)
```

Returns the `System.Guid` representation of a grain primary key.

### Parameters

- `grainId` (`GrainId`): The grain to find the primary key for.

### Returns

A `System.Guid` representing the primary key for this grain.

## GetGuidKey(GrainId, string?) {#getguidkey-this-orleans-runtime-grainid-out-string-nullable-6e57ac1b}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainidkeyextensions/methods/getguidkey-this-orleans-runtime-grainid-out-string-nullable-6e57ac1b/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/GrainIdKeyExtensions.cs#L310-L315)

```csharp
public static Guid GetGuidKey(this GrainId grainId, out string? keyExt)
```

Returns the `System.Guid` representation of a grain primary key.

### Parameters

- `grainId` (`GrainId`): The grain to find the primary key for.
- `keyExt` (`string?`): The output parameter to return the extended key part of the grain primary key, if extended primary key was provided for that grain.

### Returns

A `System.Guid` representing the primary key for this grain.

## GetIntegerKey(GrainId) {#getintegerkey-this-orleans-runtime-grainid-fd77f2db}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainidkeyextensions/methods/getintegerkey-this-orleans-runtime-grainid-fd77f2db/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/GrainIdKeyExtensions.cs#L233-L238)

```csharp
public static long GetIntegerKey(this GrainId grainId)
```

Returns the `System.Int64` representation of a grain key.

### Parameters

- `grainId` (`GrainId`): The grain to find the key for.

### Returns

A `System.Int64` representing the key for this grain.

## GetIntegerKey(GrainId, string?) {#getintegerkey-this-orleans-runtime-grainid-out-string-nullable-3d3071ff}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainidkeyextensions/methods/getintegerkey-this-orleans-runtime-grainid-out-string-nullable-3d3071ff/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/GrainIdKeyExtensions.cs#L218-L223)

```csharp
public static long GetIntegerKey(this GrainId grainId, out string? keyExt)
```

Returns the `System.Int64` representation of a grain key.

### Parameters

- `grainId` (`GrainId`): The grain id.
- `keyExt` (`string?`): The output parameter to return the extended key part of the grain primary key, if extended primary key was provided for that grain.

### Returns

A long representing the key for this grain.

## TryGetGuidKey(GrainId, Guid, string?) {#trygetguidkey-this-orleans-runtime-grainid-out-system-guid-out-string-nullable-c3d9da7f}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainidkeyextensions/methods/trygetguidkey-this-orleans-runtime-grainid-out-system-guid-out-string-nullable-c3d9da7f/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/GrainIdKeyExtensions.cs#L258-L271)

```csharp
public static bool TryGetGuidKey(this GrainId grainId, out Guid key, out string? keyExt)
```

Tries to parse the [GrainId](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/) portion of the provided grain id to extract a `System.Guid` key and `System.String` key extension.

### Parameters

- `grainId` (`GrainId`): The grain id.
- `key` (`Guid`): The key.
- `keyExt` (`string?`): The key extension.

### Returns

`true` when the grain id was successfully parsed, `false` otherwise.

## TryGetIntegerKey(GrainId, long, string?) {#trygetintegerkey-this-orleans-runtime-grainid-out-long-out-string-nullable-904afb83}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainidkeyextensions/methods/trygetintegerkey-this-orleans-runtime-grainid-out-long-out-string-nullable-904afb83/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/GrainIdKeyExtensions.cs#L178-L186)

```csharp
public static bool TryGetIntegerKey(this GrainId grainId, out long key, out string? keyExt)
```

Tries to parse the [GrainId](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.grainid/) portion of the provided grain id to extract a `System.Int64` key and `System.String` key extension.

### Parameters

- `grainId` (`GrainId`): The grain id.
- `key` (`long`): The key.
- `keyExt` (`string?`): The key extension.

### Returns

`true` when the grain id was successfully parsed, `false` otherwise.
