public sealed class Reference<T>
{
private static ulong maxID = 0;
private ulong id = maxID++;
public ulong LongID => this.id;
public Reference() { }
public bool Equals(T? other)
=> other?.Reference.id == this.id;
public bool Equals(Reference<T>? other)
=> other?.id == this.id;
public override bool Equals(object? obj)
=> obj is T it ? Equals(it) : obj is Reference<T> rf ? Equals(rf) : false;
public override int GetHashCode() => HashCode.Combine(this.id);
public static bool operator ==(Reference<T>? left, Reference<T>? right)
=> left?.Equals(right) ?? false;
public static bool operator !=(Reference<T>? left, Reference<T>? right)
=> !(left == right);
public override string ToString() => $"Reference<{typeof(T).Name}> ({this.id})";
}
In this code i have class Reference<T> with static field.
if i create new instance, hes got individual id
new Reference<T>(); id equals 0
new Reference<T>(); id equals 1
In dotnet when you use generic type under hood created new non-generic type
I think that Reference<T>.maxID has value 2 and Reference<T2>.maxID 0
But this fields non-generic, and it is quite possible that fields are sames in different generic types