A property set as private or without private keyword. What is the difference?

c#, properties

Solution

For the case `public string Name { get; private set; }` Using private set means that the property is `ReadOnly` from 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 :

private string _Name;
public string Name
{
    get { return _Name; }
    private set { _Name = value; }
}

Problem

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?

Original source