是否存在IEnumerable <T>,该IEnumerable <T>是(1)保证不同元素(2)在T上协变的?

时间:2019-07-16 02:22:40

标签: c# .net oop design-patterns

根据我的测试,即使IImmutableSet<T>都没有给我,我感到很惊讶。

   Type                  |  Distinct Elements? | Covariant on T
================================================================
      IEnumerable<T>     |        No           |      Yes
----------------------------------------------------------------
 IReadOnlyCollection<T>  |        No           |      Yes
----------------------------------------------------------------
        ISet<T>          |        Yes          |      No
----------------------------------------------------------------
      IImmutableSet<T>   |        Yes          |      No 
================================================================   

我的用例是当我想定义一个接口时

interface IFoo<out T> where T : IBar
{
     // want to at least indicate to consumer of the class that these are distinct
     IImmutableSet<T> Bars { get; } 

     // ... 

}

0 个答案:

没有答案