# IdSpan Methods

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

## AsSpan {#asspan-8e26224c}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/methods/asspan-8e26224c/)

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

```csharp
public ReadOnlySpan<byte> AsSpan()
```

Returns a span representation of this instance.

### Returns

A span representation of this instance.

## CompareTo(IdSpan) {#compareto-orleans-runtime-idspan-d7f8aa44}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/methods/compareto-orleans-runtime-idspan-d7f8aa44/)

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

```csharp
public int CompareTo(IdSpan 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` (`IdSpan`): 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(string) {#create-string-567e4163}

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

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

```csharp
public static IdSpan Create(string id)
```

Creates a new [IdSpan](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/) instance from the provided value.

### Parameters

- `id` (`string`)

### Returns

A new [IdSpan](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/) corresponding to the provided id.

## Equals(IdSpan) {#equals-orleans-runtime-idspan-4d856c2f}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/methods/equals-orleans-runtime-idspan-4d856c2f/)

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

```csharp
public bool Equals(IdSpan obj)
```

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

### Parameters

- `obj` (`IdSpan`): 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-ea443528}

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

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

```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-54eeeb76}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/methods/gethashcode-54eeeb76/)

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

```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-a5eb8279}

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

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/IdSpan.cs#L126-L128)

```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-9716cc8f}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/methods/getuniformhashcode-9716cc8f/)

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

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

Returns a uniform, stable hash code for an [IdSpan](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/).

### Returns

The hash code of this instance.

## ToString {#tostring-a4120eb7}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/methods/tostring-a4120eb7/)

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

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

Returns a string representation of this instance, decoding the value as UTF8.

### Returns

A string representation fo this instance.

## TryFormat(Span&lt;char&gt;, int) {#tryformat-system-span-char-out-int-d83e8119}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/methods/tryformat-system-span-char-out-int-d83e8119/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/IDs/IdSpan.cs#L180-L194)

```csharp
public bool TryFormat(Span<char> destination, out int charsWritten)
```

### Parameters

- `destination` (`Span<char>`)
- `charsWritten` (`int`)

## UnsafeCreate(byte[]?, int) {#unsafecreate-byte-array-1-nullable-int-2d00b847}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/methods/unsafecreate-byte-array-1-nullable-int-2d00b847/)

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

```csharp
public static IdSpan UnsafeCreate(byte[]? value, int hashCode)
```

Creates an instance, specifying both the hash code and the value.

### Parameters

- `value` (`byte[]?`): The underlying value.
- `hashCode` (`int`): The hash of the underlying value.

### Returns

An [IdSpan](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/) instance.

## UnsafeGetArray(IdSpan) {#unsafegetarray-orleans-runtime-idspan-db27fa88}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/methods/unsafegetarray-orleans-runtime-idspan-db27fa88/)

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

```csharp
public static byte[]? UnsafeGetArray(IdSpan id)
```

Gets the underlying array from this instance.

### Parameters

- `id` (`IdSpan`): The id span.

### Returns

The underlying array from this instance.

## operator ==(IdSpan, IdSpan) {#op-equality-orleans-runtime-idspan-orleans-runtime-idspan-684b7781}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idspan/methods/op-equality-orleans-runtime-idspan-orleans-runtime-idspan-684b7781/)

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

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

Compares the provided operands for equality.

### Parameters

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

### Returns

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

## operator !=(IdSpan, IdSpan) {#op-inequality-orleans-runtime-idspan-orleans-runtime-idspan-75356255}

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

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

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

Compares the provided operands for inequality.

### Parameters

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

### Returns

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