William Thompson

William Thompson

  • 1.6k
  • 155
  • 298.8k

Is { get; set; } useful?

Jun 29 2018 2:56 PM
from time to time, I see some sample code that is handed to me that has a code snippet that looks like this:
  1. public string Name { getset; }  
Does this actually do anything? Does it really make it so that one can set and get the "Name" string variable?
 
I have always thought that what is required is something like this:
  1. private string name;  
  2.   
  3.         public string Name  
  4.         {  
  5.             get  
  6.             {  
  7.                 return this.name;  
  8.             }  
  9.             set  
  10.             {  
  11.                 this.name = value;  
  12.             }  
  13.         }  
Am I correct?
Please advise.

Answers (4)