Is Get; Set property syntaxes makes any difference?

105 views Asked by At

I am new to C# language. There are different syntax for Get; Set property. Like

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


public string Name 
    { 
      get { return _name; }
      set { _name = value; }
    }

protected string Name { get; set; }

What is the difference between these syntax? Does following different syntax have any impact on functionality? or all the syntax will perform same function?

1

There are 1 answers

0
Pavel Krymets On BEST ANSWER

First two syntaxes are exactly the same, because you can safle omit this keyword.

Third works exactly the same but generates backing field automatically making the code shorter and easier to write.