Search code examples
c#.netgenericsienumerable

generic NOT constraint where T : !IEnumerable


As per the title, is it possible to declare type-negating constraints in c# 4 ?

The use-case of interest was to allow the following overloads to co-exist

    void doIt<T>(T what){} 
    
    void doIt<T>(IEnumerable<T> whats){}

At the moment there is ambiguity because T in the first method could be an IEnumerable<> (so I would like to specify that T should NOT be IEnumerable)


Solution

  • No - there's no such concept either in C# or in the CLR.