Consider this class
public sealed record IdValuePair<TId, TValue>
{
public IdValuePair(TId id, TValue value)
{
EnsureArg.HasValue(value, nameof(value));
Id = id;
Value = value;
}
public IdValuePair(TValue value)
{
EnsureArg.HasValue(value, nameof(value));
Id = default!;
Value = value;
}
public TId Id { get; }
public TValue Value { get; }
}
Why is it that if I add the generic constraint
where TId : notnull
I am unable to do this assignment, due to the below error:
Id = default;
CS8601 Possible null reference assignment.
Doesn't the notnull
constraint ensure that TId
is not null?