Creating an empty sequence using the Empty operator in LINQ
August 16, 2016 4 Comments
You can create an empty sequence of a type using the Empty operator in Linq. Its usage is very simple:
IEnumerable<string> emptyStringSequence = Enumerable.Empty<string>();
This creates a sequence of strings consisting of 0 elements.
Nice little nugget of info, thanks! Always enjoy reading your blog.
Hi Andras.
When would you need to do that?
Hi Brent, look at the following post: http://geekswithblogs.net/BlackRabbitCoder/archive/2011/04/21/c.net-little-wonders-any-and-all.aspx
Ahh. So it looks like this will initialize the collection without populating it.
Thanks Andras.