Nlog
SQLite
var dict = new Dictionary<MyNullableInt, string>();
dict[null] = "hello, world!";
Console.WriteLine(dict[null]); // Output: hello, world!
struct MyNullableInt: IEquatable<MyNullableInt>, IEquatable<int?>
{
public int? Value { get; set; }
public bool Equals(MyNullableInt other)
{
return other.Value == Value;
}
public bool Equals(int? other)
{
return other == Value;
}
public static implicit operator MyNullableInt(int? value)
{
return new MyNullableInt() {Value = value};
}
public static implicit operator int?(MyNullableInt value)
{
return value.Value;
}
public override bool Equals(object? obj)
{
if (obj is int value)
{
return value == Value;
}
if (obj is MyNullableInt mni)
{
return mni.Value == Value;
}
return false;
}
public override int GetHashCode()
{
return Value.GetHashCode();
}
}