• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

C# get/set property question

 
Bobby Sharma
Ranch Hand
Posts: 598
3
Google App Engine jQuery Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know difference between these two code snippet.


and this one.



please explain.
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first version uses "automatic properties", which are syntactic sugar: if you want a simple getter/setter pair you can use this and the private backing variable will be automatically declared (and hidden from you) - it's a short-cut.

Which means that the example isn't right - you shouldn't also declare private variables. The correct idiom is:
 
Bobby Sharma
Ranch Hand
Posts: 598
3
Google App Engine jQuery Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good explanation. thank you, Matthew.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic