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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:40:09+00:00 2026-06-12T05:40:09+00:00

Why I can implement a read-only property like so… public IList<object> SelectedItems { get;

  • 0

Why I can implement a read-only property like so…

public IList<object> SelectedItems { get; }

…and still be able to use its members, like Add, Remove, etc. when I use the property ?

Isn’t readonly supposed to be readonly “all the way down” ?

  • 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-12T05:40:11+00:00Added an answer on June 12, 2026 at 5:40 am

    isn’t readonly supposed to be readonly “all the way down” ?

    1. This isn’t a “readonly” type. It’s a property where you can retrieve the value (the IList<object>), but can’t set the value to a different instance of IList<object> as there is no property setter.

    2. No. It’s not readonly “all the way down” – the fact that the property only has a getter means you can get the value, but you can do anything you wish with it.

    Note that I’d be careful using the term “readonly”. C# has a different, distinct meaning and dedicated readonly keyword, which applies only to fields. This isn’t “readonly” in the C# meaning, but a property which only provides a get operation.

    If you want to have a “read only” list, a good option is to return a ReadOnlyCollection<T>. For example, if your internal class is a List<T>, you can use:

    public IList<object> SelectedItems { get { return this.selected.AsReadOnly(); } }
    

    If you are going to do this, it might be better to actually return the ReadOnlyCollection<T> as well:

    public ReadOnlyCollection<object> SelectedItems { get { return this.selected.AsReadOnly(); } }
    

    This way, users won’t expect that it’s safe to call .Add() on the resulting list.

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

Sidebar

Related Questions

Possible Duplicate: Can Read-Only Properties be Implemented in Pure JavaScript? I have an Object
I'm wondering how to best implement a property (here, LatestRequest ) which is read-only,
I'd like to know if I can implement a method on MemoryCache that removes
For Binary serialization I use public ClassConstructor(SerializationInfo info, StreamingContext ctxt) { this.cars = (OtherClass)info.GetValue(Object,
Consider the class: public class foo { public object newObject { get { return
I can implement both variants - it's easy. But I'm interested: what approach is
How can implement reordring in winforms datagridview by using the feature of drag and
Can someone please tell me how I can implement the following line of pseudo-code.
Anyone knows how i can implement re-arrangable divs (Drag the divs around on the
How I can implement dynamic Jtree, which shows created instances of clases? For example,

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.