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

  • SEARCH
  • Home
  • 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 8523771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:30:17+00:00 2026-06-11T07:30:17+00:00

Possible Duplicate: Why was IEnumerable<T> made covariant in C# 4? I was taking a

  • 0

Possible Duplicate:
Why was IEnumerable<T> made covariant in C# 4?

I was taking a look on MSDN for IEnumerable<T> interface definition, and see:

public interface IEnumerable<out T> : IEnumerable

I was wondering why T is defined as out, why not?

public interface IEnumerable<T> : IEnumerable

What is the reason for this?

  • 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-11T07:30:18+00:00Added an answer on June 11, 2026 at 7:30 am

    More information can be found here.

    The out makes the type parameter covariant. That is, you can use either the type or any derived types. Note that out only works this way with generics, it has a different meaning when used in method signatures (though you probably already knew that).

    Here is the example taken from the referenced page:

    // Covariant interface. 
    interface ICovariant<out R> { }
    
    // Extending covariant interface. 
    interface IExtCovariant<out R> : ICovariant<R> { }
    
    // Implementing covariant interface. 
    class Sample<R> : ICovariant<R> { }
    
    class Program
    {
        static void Test()
        {
            ICovariant<Object> iobj = new Sample<Object>();
            ICovariant<String> istr = new Sample<String>();
    
            // You can assign istr to iobj because 
            // the ICovariant interface is covariant.
            iobj = istr;
        }
    }
    

    As you can see, the out in the interface signature allows
    you to assign an ICovariant<String> to an ICovariant<Object> variable, as String derives from Object. Without the out keyword, you would be unable to do this, as the types would be different.

    You can read more about covariance (and the related contravariance) here.

    As other answers have pointed out, IEnumerable was only made covariant in .NET 4. Trying to write code such as:

    IEnumerable<Object> strings = new List<string>();
    

    will compile in .NET 4 and later versions, but not in previous versions.

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

Sidebar

Related Questions

Possible Duplicate: LINQ equivalent of foreach for IEnumerable<T> please help me to figure out
Possible Duplicate: Why is there not a ForEach extension method on the IEnumerable interface?
Possible Duplicate: Why is there not a ForEach extension method on the IEnumerable interface?
Possible Duplicate: LINQ equivalent of foreach for IEnumerable<T> I'm wondering whether there is a
Possible Duplicate: Recreating a Dictionary from an IEnumerable When using the Where method on
Possible Duplicate: C# Cannot convert from IEnumerable<Base> to IEnumerable<Derived> I have D1 and D2
Possible Duplicate: IEnumerable.Cast<> One can implicitly convert from int to double. Why does Specified
Possible Duplicate: Convert IEnumerable to DataTable I just want to Convert a List or
Possible Duplicate: Can anyone explain IEnumerable and IEnumerator to me? What are the differences
Possible Duplicate: Find sequence in IEnumerable<T> using Linq There is a string method: int

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.