Is there an Empty List singleton in C#? - Stack Overflow Using Enumerable Empty<T>() with lists has a drawback If you hand Enumerable Empty<T> into the list constructor then an array of size 4 is allocated But if you hand an empty Collection into the list constructor then no allocation occurs So if you use this solution throughout your code then most likely one of the IEnumerable s will be used to construct a list, resulting in unnecessary
c# - How to get an empty list of a collection? - Stack Overflow I have a collection of anonymous class and I want to return an empty list of it What is the best readable expression to use? I though of the following but I don't think they are readably enough:
Return empty List lt;T gt; or null when no list items present? I'd definitely return an empty list so methods can still be called on the object without requiring null checks There's a difference between returning an empty list and returning nothing at all, so the calling code probably isn't expecting to receive a null reference anyway (unless an exception occurs or something)
c# - Enumerable. Empty to List - Stack Overflow 3 Actually Enumerable Empty returns an empty array, that's why you get the NotSupportedException in Array IList Add Arrays have a fixed size Why array implements IList? I would return null instead of an empty sequence if you want to "signal that there was an error" A type check for your business logic is not good in terms of readability