asd.Value?.GroupBy(x => x.ParentId == null ? 0 : x.ParentId).ToDictionary(gg => gg.Key, gg => gg.ToList());
asd.Value?.GroupBy(x => x.ParentId??0 ).ToDictionary(gg => gg.Key, gg => gg.ToList());
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();
}
}