C# Fundamentals: Returning Zero or One Item As IEnumerable<T>(blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 5 months, 17 days ago

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.

2 comments |category: |Views: 40

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by BlackRabbitCoderBlackRabbitCoder(661) 5 months, 17 days ago 0

New post!

Reply

posted by dpetersondpeterson(4397) 5 months, 16 days ago 0

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.

Reply

information Login or create an account to comment on this story