C# Fundamentals: Returning Zero or One Item As IEnumerable<T>

added by BlackRabbitCoder
12/9/2011 8:49:33 AM

1 Kicks, 114 Views

There are times when we are writing a method that returns a sequence of items, that it occasionally becomes necessary in base-class, interface implementation, error, or default conditions to return a sequence of only one or even zero items. There are many ways to do this, of course, which begs the question of which way is best, in terms of readability, maintainability, and performance.


12/8/2011 6:36:43 PM
New post!

12/9/2011 8:49:21 AM
I was expecting array to be the fastest method until I saw Enumerable.Empty<T>(). That's actually the first I've heard of it, go figure. Thanks for sharing.