1

I'd like to ask a question about the following simple code:

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

What is the point in this case to create "name" private and then another string "Name" which just reads name and sets name? Is this considered encapsulation? Why shouldn't we just do the following?:

    public string name
    {
    get;
    private set;
    }

And then for example have a method called "SetName" which whould change the name value. Which is considered more correct way to encapsulate? Thank you!

user3604597
  • 251
  • 1
  • 5
  • 8
  • Also [Using a SetProperty method to prevent accidental changes to a property](http://programmers.stackexchange.com/questions/117142/using-a-setproperty-method-to-prevent-accidental-changes-to-a-property) – Alex K. Nov 27 '14 at 17:03

0 Answers0