Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8137773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:16:04+00:00 2026-06-06T11:16:04+00:00

Context: I sent an email to my colleagues telling them about Enumerable.Empty<T>() as a

  • 0

Context: I sent an email to my colleagues telling them about Enumerable.Empty<T>() as a way to return empty collections without doing something like return new List<T>(); I got a reply saying that the downside is that it doesn’t expose a specific type:

That does present a tiny issue. It’s always good to be as specific as possible about your return type* (so if you’re returning a List<>, make that your return type); that’s because things like Lists and Arrays have extra methods that are useful. Plus it also can be useful in making performance considerations when using the collection from the calling method.

The trick below unfortunately forces you to return an IEnumerable, which is about as non-specific as possible, right? 🙁

* This is actually from the .NET Design Guidelines. Stated reasons in the guidelines are the same as I’m mentioning here, I believe.

This seemed to be the complete opposite of what I had learned, and try as I might, I couldn’t find this exact advice in the design guidelines. I did find one small piece like this:

DO return a subclass of Collection<T> or ReadOnlyConnection<T> from very commonly used methods and properties.

With a code snippet following, but no more justification at all.


So that being said, is this a real and accepted guideline (the way it was described in the first block quote)? Or has it been misinterpreted? All other SO questions I could find have answers preferring IEnumerable<T> as the return type. Maybe the original .NET guidelines are just outdated?

Or maybe it’s not so clear cut? Are there some tradeoffs to consider? When would it be a good idea to return a more specific type? Is it ever recommended to return a concrete generic type, or only to return a more specific interface like IList<T> and ReadOnlyCollection<T>?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:16:05+00:00Added an answer on June 6, 2026 at 11:16 am

    There are reasons for both styles:

    1. Be specific: You are making a guarantee to callers that you will always return this type. Even when your implementation changes. Can you keep the promise? If yes, be specific to let callers benefit. More derived types have more features.
    2. Be generic: If you are likely to change the underlying implementation of the method or property in question, you can’t promise a List<T>. Maybe you can promise an IList<T> or a custom collection class (which you can change later).

    The .NET framework BCL goes with either arrays or custom collection classes. They need to provide a 100% stable API so they need to be careful.

    In normal software projects you can change the caller (which the .NET framework guys can’t), so you can be more lenient. If you promise too much, and need to change that a year later, you can do that (with some effort).

    There is only one thing that is always wrong: Saying that one should always do (1) or (2). Always is always wrong.

    Here is an example for a case where specificity is clearly the right choice:

        public static T[] Slice<T>(this T[] list, int start, int count)
        {
            var result = new T[count];
            Array.Copy(list, start, result, 0, count);
            return result;
        }
    

    There is only one reasonable implementation possible, so we can clearly promise that the return type is an array. We will never need to return a list.

    On the other hand, a method to return all users from some persistent store might change a lot internally. The data might even be bigger than available memory, which requires streaming. We should probably choose IEnumerable<User>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Context Clojure Agents are NOT sent new values. They are sent a function which
Context I'm currently reading about Clojure's implementation of monads: org.clojure/algo.monads Intuitively, reduce looks like
I have created aand sent a short email with a .txt attachment in an
Is there any way how to send digital signed email with pear Mail? I
I can read attachments sent from all email clients I've tested except for androids
i have printer status reports sent on my email. i would like to download
Written a code for send an email along attachment. Once I sent this email
I about 100 emails in my inbox this morning telling me various pages don't
I have following code which successfully sent email using Gmail address. But when i
It appears the true From tag of a message sent from an email service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.