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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
When use use a
private setwhat that means is that the property itself is un-setable from outside the class, not that it’s methods are not available, andList<T>.Add()is only a method that the compiler knows nothing about.By example:
Take a look at this question, where use of the
ReadOnlyCollectionclass is explained in the case when you want to restrict access to the collection itself, as well as the reference to the collection.