Can we specify the access modifiers for the get and set accessors in a property?

 Posted by Ddd on 1/19/2011 | Category: C# Interview questions | Views: 4154 | Points: 40
Answer:

Yes, we can specify the access modifiers for the get and set accessors in a property

Example:

internal string myname
{
private set;
get;


}

This is Ok

Note:
1)The access modifier for the accessor must be more restrictive than that of the property.

private is more restrictive than internal.

2)Both get and set accessors cannot have access modifiers in the same property.

private set and private get would be WRONG in the above example.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response