'Shouldn't ILookup<TKey, TElement> be (declared) covariant in TElement?
The definition System.Linq.ILookUp<TKey, TElement> reads
interface ILookup<TKey, TElement> : IEnumerable<IGrouping<TKey, TElement>>, IEnumerable
{
int Count { get; }
IEnumerable<TElement> this[TKey key] { get; }
bool Contains(TKey key);
}
Since IEnumerable is covariant in IGrouping<TKey, TElement> , IGrouping<TKey, TElement> is covariant in TElement and the interface only exposes TElement as a return type, I would assume that ILookup is also covariant in TElement. Indeed, the definition
interface IMyLookup<TKey, out TElement> : IEnumerable<IGrouping<TKey, TElement>>, IEnumerable
{
int Count { get; }
IEnumerable<TElement> this[TKey key] { get; }
bool Contains(TKey key);
}
compiles without problems.
So, what might be the reason why the out keyword is missing in the original definition? Might it be added future versions of Linq?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
