access modifiers applied to property

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roy

    access modifiers applied to property

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

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

    #2
    Re: access modifiers applied to property

    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" <Roy@discussion s.microsoft.com wrote in message
    news:B368D0E4-28FE-47BC-8CC1-130D5BADE57C@mi crosoft.com...
    If I define a property as
    int age
    {
    get;
    set;
    }
    >
    Is there a way to add different access modifiers to the accessors when
    implement?

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: access modifiers applied to property

      Roy <Roy@discussion s.microsoft.com wrote:
      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; }
      }

      --
      Jon Skeet - <skeet@pobox.co m>
      http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
      If replying to the group, please do not mail me too

      Comment

      Working...