I am setting the property of a class like that
public string Name { get; set; }
But i can also set the property like that
public string Name { get; private set; }
I want to know the difference between these? and what scope they have?
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.
For the case
public string Name { get; private set; }Using private set means that the property is
ReadOnlyfrom the outside. Its useful when you have a read only property and don’t want to explicitly declare the backing variable.public string Name { get; private set; }it is same as :