Why do automatic properties require both getters AND setters?

In C#, if I declare an auto-implemented property, why do I have to declare BOTH the get and set part?


public string ThisWorks { get; set; }

public string ThisDoesnt { get; }

Isn't this just syntactic sugar - i.e. the compiler inserts a private field for the property? So why the problem?



If you didn't have a setter - then how would you ever set the property?

Incidentally, you can specify the accessibility, eg:

public string Foo
  private set;

Need Your Help

Passing a parameter through server.execute?

asp-classic parameter-passing

It is possible to pass a parameter through server.execute?

Jquery check list of elements for a match

javascript jquery

I have some checkboxes grouped using the attribute rel. When anyone is unchecked, I want to check if all are also unchecked, then do something.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.