I'm converting code in preparation to C#9, in particular the below class implementing IGrouping<TKey, TElement>
:
public class Grouping<TKey, TElement> : IGrouping<TKey, TElement>
{
public TKey Key { get; }
public Grouping(TKey key, IEnumerable<TElement> elements)
{
Key = key;
_elements = elements;
}
private readonly IEnumerable<TElement> _elements;
...
}
Lookups support null keys so in theory the constructor should be:
public Grouping(TKey? key, IEnumerable<TElement> elements)
but then Key = key;
raises a warning since Key
is not defined as TKey?
(as per the interface's specs).
I feel like something missing in the interface's definition but maybe am I missing something?