Skip to content
CShift0.45

Handle<T>

Struct · namespace System · Since 0.42

struct Handle<T> : IEquatable<Handle<T>>, IHashable

A handle to an element of a SlotMap: where it is (Slot) and which occupant of that place it means (Generation). Handles are plain values (two ints, no reference count): they can be copied, kept in structs, used as Dictionary keys and passed to threads, and they never keep an element alive or form a cycle.

A handle stays valid until its element is removed; after that it is stale and the map rejects it, also when the place has a new occupant. The zero value (new(), a field without a value) is never valid: a “no element” handle. The type argument keeps handles of different maps apart: a Handle<Unit> does not fit a SlotMap<Item>.

Name Description
Slot The place in the map.
Generation The occupant of that place (odd numbers, from 1; 0 is never valid).
int Slot

The place in the map.

int Generation

The occupant of that place (odd numbers, from 1; 0 is never valid).

Name Description
IsNone Whether this is the zero value, which refers to no element.
Equals Whether both refer to the same place and occupant.
GetHashCode A hash code of the place and the occupant.
ToString The handle as text: #3.1 (place 3, occupant 1).
bool IsNone()

Whether this is the zero value, which refers to no element.

bool Equals(Handle<T> other)

Whether both refer to the same place and occupant.

int GetHashCode()

A hash code of the place and the occupant.

string ToString()

The handle as text: #3.1 (place 3, occupant 1).