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 8045087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:26:06+00:00 2026-06-05T05:26:06+00:00

What is the difference between <out T> and <T> ? For example: public interface

  • 0

What is the difference between <out T> and <T>? For example:

public interface IExample<out T>
{
    ...
}

vs.

public interface IExample<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-05T05:26:08+00:00Added an answer on June 5, 2026 at 5:26 am

    The out keyword in generics is used to denote that the type T in the interface is covariant. See Covariance and contravariance for details.

    The classic example is IEnumerable<out T>. Since IEnumerable<out T> is covariant, you’re allowed to do the following:

    IEnumerable<string> strings = new List<string>();
    IEnumerable<object> objects = strings;
    

    The second line above would fail if this wasn’t covariant, even though logically it should work, since string derives from object. Before variance in generic interfaces was added to C# and VB.NET (in .NET 4 with VS 2010), this was a compile time error.

    After .NET 4, IEnumerable<T> was marked covariant, and became IEnumerable<out T>. Since IEnumerable<out T> only uses the elements within it, and never adds/changes them, it’s safe for it to treat an enumerable collection of strings as an enumerable collection of objects, which means it’s covariant.

    This wouldn’t work with a type like IList<T>, since IList<T> has an Add method. Suppose this would be allowed:

    IList<string> strings = new List<string>();
    IList<object> objects = strings;  // NOTE: Fails at compile time
    

    You could then call:

    objects.Add(7); // This should work, since IList<object> should let us add **any** object
    

    This would, of course, fail – so IList<T> can’t be marked covariant.

    There is also, btw, an option for in – which is used by things like comparison interfaces. IComparer<in T>, for example, works the opposite way. You can use a concrete IComparer<Foo> directly as an IComparer<Bar> if Bar is a subclass of Foo, because the IComparer<in T> interface is contravariant.

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

Sidebar

Related Questions

Can you please describe an example indicating difference between Public and Private Cache-Control in
I am trying to figure out the difference between Memcached and JPA, this is
I am trying to figure out the difference between Google's GData API ( http://code.google.com/p/gdata-python-client/
What's the difference between cat int.txt > out.txt and cat int.txt >> out.txt Does
I am confused and couldn't figure out the difference between these two lines!! echo
System.out.println(matcher.group(1)); System.out.println(matcher.group()); I like to know what's the difference between the above two codes.
I am trying to figure out what the difference is between onKeyPress and onKeyUp.
I have been trying to find out what the difference is between the IS
I am trying to find out about the performance difference between normal multithreading and
Can someone please explain to me what is the difference between protected / public

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.