Why is property setter is defaulted to public

Why is the default access modifier of getters and setters is public and not private?


The get and set portions of a property are not defaulted to public, they are defaulted to whichever is the visibility of the property they belong to. The default visibility of the property iself is private, as for all other kinds of members.

Because it's how C# was designed.

  • Defined fields
  • Define property to access that field

So expected default behaviour that you make field private and make property in a way to be able to write and read to the field from the caller (arbitrary, not only derived one), so the property and get/set methods (if not there is no any sense making property public) becomes public.

This is just expected default behaviour, and nothing else.

I think it is because the property has own access modifier and in fact describes a set of two methods: SomeType getProp() and void setProp(SomeType). These methods are seen like the property by default. But if you want to change their visibility you can do it using additional modifiers(for example Prop{get;private set;}).

Need Your Help

Is it possible to do pattern matching with given value in SML?

pattern-matching sml

In Scala it is possible, so I wonder if this possible in SML as well, consider such code:

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.