If you want to create an empty IEnumerable of type T, you can create it using the static generic method
Enumerable.Empty<T>()
See here for more info.
Why did Microsoft go for this option instead of using a static method on the generic type ( as opposed to a generic static method on the non-generic type ) ?
This method could be used like this :
Enumerable<T>.Empty()
Which would then return an empty IEnumerable<T>.
In my opinion, the second option makes more sense since what I want to create is the generic IEnumerable<T>, not a non-generic IEnumerable.
Edit: typo
IEnumerable<T>is an interface.Interfaces cannot contain static members.
The static method is actually on the
Enumerabletype, which is a non-genericstaticclass.Therefore, there is no
Enumerable<T>generic class that could contain the method.Static members on generic types should be avoided.
Extension methods cannot be placed in a generic type.
This is why the static
Enumerableclass is not generic.