Is there an “Empty List” singleton in C#?
In C# I use LINQ and IEnumerable a good bit. And all is well-and-good (or at least mostly so). However, in many cases I find myself that I need an empty IEnumerable<X> as a default. That is, I would like for (var x in xs) { ... } to work without needing a null-check. Now this is what I currently do, depending upon the larger context: var xs = f() ?? new X[0]; // when xs is assigned, sometimes for (var x in xs ?? new X[0]) { ... } // inline, sometimes Now, while the above is perfectly fine for me -- that is, if there is any "extra overhead" with creating the array object I just don't care -- I