access modifiers applied to property

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If I define a property as
int age
{
get;
set;
}

Is there a way to add different access modifiers to the accessors when
implement?
 
Yes ... sort of ...

You could use an explicit interface implementation but the items will still
be publicly visible if casted to the interface.

Cheers,

Greg
 
Roy said:
If I define a property as
int age
{
get;
set;
}

Is there a way to add different access modifiers to the accessors when
implement?

If you've put that in the interface, they're public and *have* to be
public.

If you just mean the normal declaration of a property, you can indeed
specify them differently - but only in 2.0.

For example:

public int Age
{
get { return age; }
private set { age = value; }
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top