Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different access modifier of properties?

Tags:

c#

asp.net

i have doubt, can we have different access modifier for get and set in a property.

Thank you,

like image 379
Surya sasidhar Avatar asked Dec 12 '22 13:12

Surya sasidhar


1 Answers

Yes, you can, however it is subject to the rule that your getter/setter cannot have a less restricted access modifier than the property itself.

For example (C#):

public Foo { get; private set; } //this is okay
protected Bar { get; public set; } //this will throw a compile error
like image 85
Brian Driscoll Avatar answered Dec 15 '22 03:12

Brian Driscoll