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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:32:08+00:00 2026-06-05T22:32:08+00:00

I have been reading up on the changes that .NET4.5 will bring, and on

  • 0

I have been reading up on the changes that .NET4.5 will bring, and on this blog post I stumbled upon something I neither knew nor understood.

When talking about the implementation of readonly collections, Immo Landwerth says:

Unfortunately, our type system doesn’t allow making types of T covariant unless it has no methods that take T as an input. Therefore, we can’t add an IndexOf method to IReadOnlyList. We believe this is a small sacrifice compared to not having support for covariance.

From my obviously limited understanding, it seems like he is saying that in order to enable us to call a method that requires an IReadOnlyList<Shape> by passing in a IReadOnlyList<Circle>, we can’t have a IReadOnlyList<T>.IndexOf(T someShape) method.

I don’t see how the type system would prevent that. Can someone explain?

  • 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-05T22:32:11+00:00Added an answer on June 5, 2026 at 10:32 pm

    Suppose Circle implements IEquatable<Circle>. That would naturally be used by IReadOnlyList<Circle>.IndexOf if it were available. Now if you could write this:

    IReadOnlyList<Circle> circles = ...;
    IReadOnlyList<Shape> shapes = circles;
    int index = shapes.IndexOf(new Square(10));
    

    that would end up trying to pass a Square to Circle.Equals(Circle) which would clearly be a bad idea.

    The rules which enforce the “no values of T in input positions” are in section 13.1.3 of the C# 4 spec. You should also read Eric Lippert’s blog series on generic variance for a lot more details.

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

Sidebar

Related Questions

i have been reading this interesting article which is increasing my every growing confusion
I have been reading through this wonderful website regarding the recommended Python IDEs and
I have been reading a lot about HTML 5 and some of the changes
I have been reading a lot about test-driven development and decided that I want
I have been reading up on using webrequests and post and get methods to
I have been reading through this similar question and find myself less than satisfied
I have been reading this paper titled Clone Detection using Abstract Syntax Trees by
Have been reading about async and tasks and been attempting to convert the CopyFileEx
I have been reading up on multiple PHP frameworks, especially the Zend Framework but
I have been reading the docs and playing with different EventQuery parameters for days

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.