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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:53:24+00:00 2026-05-13T22:53:24+00:00

The IList<T> interface includes access by index in addition to operations not supported by

  • 0

The IList<T> interface includes access by index in addition to operations not supported by the SortedList<TKey, TValue>.Keys property such as Add, Remove, and Insert.

A ReadOnlyCollection<T>, such as the return value of List<T>.AsReadOnly, implements IList<T> and therefore offers access by index but hides illegal operations like Add, etc. by implementing them explicitly. Furthermore, it is merely a wrapper for the underlying list; so it does not create a copy and should therefore (I would assume) not incur any real performance hit.

Any idea why SortedList<TKey, TValue.Keys isn’t a ReadOnlyCollection<TKey>? (And for that matter why the Values property isn’t a ReadOnlyColllection<TValue>?)

  • 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-05-13T22:53:24+00:00Added an answer on May 13, 2026 at 10:53 pm

    This is pretty obscure, but I think this is an optimization. It has something to do with the way generics are implemented. The machine code for a generic class method is created at runtime by the JIT compiler. It needs to make several concrete versions of it. There is one for any reference type. And one each for every single value type argument that is used in a program.

    That can be inefficient, potentially lots of code that needs to be generated. Especially bad for generic framework classes, they are Ngen-ed. The concrete method implementation would have to be JIT compiled and could not be in the Ngen image.

    To combat that, there’s private code in the framework (sorry, I forgot where), that instantiates a whole raft of various versions of generic classes. Interesting do-nothing code, it puzzled me for quite a while. But the side-effect is that Ngen.exe generates code for the generic class methods. If you now use such a generic class in your own code, you’ll get the concrete implementation of the method from the Ngen image, the JIT compiler isn’t needed.

    You can see where that leads, System.Collections.ObjectModel.ReadOnlyCollection was probably deemed too obscure to get included in this list. Easily verifiable, you’ll see that when you single step into one if its methods, you won’t step into the source code, even if you got the Reference Source .pdbs.

    I’m not 100% sure this is the exact explanation. But the shoe fits.

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

Sidebar

Related Questions

I know that IList is the interface and List is the concrete type but
I've got a collection that implements an interface that extends both IList<T> and List.
I have an IList<T> that I need to sort, and I would rather not
public static IList<T> LoadObjectListAll<T>() { ISession session = CheckForExistingSession(); var cfg = new NHibernate.Cfg.Configuration().Configure();
I have an IList that contains items ( parent first ), they need to
So I have an IList of business entities that I loop through in a
I have an IList of type Breadcrumb which is just a lightweight class that
i have an IList<Animals> farmAnimals; this list has three types, Cows Sheep Chickens how
I need to enumerate though generic IList<> of objects. The contents of the list
Suppose I have one list: IList<int> originalList = new List<int>(); originalList.add(1); originalList.add(5); originalList.add(10); And

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.