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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:14:55+00:00 2026-06-15T11:14:55+00:00

I have this piece of code: public List<IVehicle> Vehicles { get; private set; }

  • 0

I have this piece of code:

public List<IVehicle> Vehicles { get; private set; }

My question is even though i am using a private set, why i can still add values to this list.

  • 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-15T11:14:56+00:00Added an answer on June 15, 2026 at 11:14 am

    When use use a private set what that means is that the property itself is un-setable from outside the class, not that it’s methods are not available, and List<T>.Add() is only a method that the compiler knows nothing about.

    By example:

    public class VehicleContainer{
       public List<IVehicle> Vehicles { get; private set; }
       ...
    }
    ....
    VehicleContainer vc = new VehicleContainer();
    vc.Vehicles  = new List<IVehicle>() // this is an error, because of the private set
    int x = vc.Vehicles.Count; // this is legal, property access
    vc.Vehicles.Add(new Vehicle()); //this is legal, method call
    

    Take a look at this question, where use of the ReadOnlyCollection class is explained in the case when you want to restrict access to the collection itself, as well as the reference to the collection.

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

Sidebar

Related Questions

I have this piece of code: public static DateDialogFragment newInstance(Context context, DateDialogFragmentListener listener) {
I have this piece of code: @Entity @Table(name = MOVERS) public class MOVers implements
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();
Context I have this piece of Java Code btn.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent
I have this piece of code List<Class<? extends SubApplication>> appClasses = new ArrayList<Class<? extends
I have written this piece of code public class Test{ public static void main(String[]
I am using spring framework 2.5.6. Says I have this piece of code: @WebMethod(operationName='hello')
I have this simple piece of code public ActionResult ListToGrid(string field, string direction) {
I have a list: public List<MyModel> MyModels { get; set; } How would I
I have this piece of code in a function. I want to print the

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.