Moose Pickard

Moose Pickard

  • NA
  • 64
  • 69.6k

Different Get/Set methods, which to use?

Sep 23 2010 7:37 AM
Hi
I recently came to the C# world. I have seen many get/set method variations. Which one do you use and I should use? 
I listed them below:

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

public string name; // Why would the name be public if it has a set/get thingy. Or is it a mistake?
public string Name
        { 
get { return name; } 
set { name = value; }}

public string name { get; set;}
public string name { get; private set;}

What are the differences between these. I like the last ones for their compactness.

Answers (4)