Accessor access modifiers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben R. Bolton

    Accessor access modifiers

    Is it possible to define a property such that the get accessor is public and
    the set accessor is private?

    Ben


  • Val Savvateev

    #2
    Re: Accessor access modifiers

    Nope. Create a private method instead of setter.

    "Ben R. Bolton" <xbridgehd@hotm ail.com> wrote in message
    news:OL7buGZbDH A.3080@TK2MSFTN GP11.phx.gbl...[color=blue]
    > Is it possible to define a property such that the get accessor is public[/color]
    and[color=blue]
    > the set accessor is private?
    >
    > Ben
    >
    >[/color]


    Comment

    • Dave Quigley[work]

      #3
      Re: Accessor access modifiers

      This is what seems wierd to me. If yo have a private set property why even
      have it at all. why not just use the member variable. your basically sayign
      i need to access a member in a class from within the same class but not
      anywhere else. It seems a waste to me to write methods and properties for
      something like this.
      "Val Savvateev" <vsavvateev@mer idium.com_NO_SP AM> wrote in message
      news:eBognQZbDH A.3080@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Nope. Create a private method instead of setter.
      >
      > "Ben R. Bolton" <xbridgehd@hotm ail.com> wrote in message
      > news:OL7buGZbDH A.3080@TK2MSFTN GP11.phx.gbl...[color=green]
      > > Is it possible to define a property such that the get accessor is public[/color]
      > and[color=green]
      > > the set accessor is private?
      > >
      > > Ben
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Val Savvateev

        #4
        Re: Accessor access modifiers

        When a dog is hungry it whines.

        Dog dog = new Dog();
        dog.IsHungry = true;

        It won't start whining if "IsHungry" is just a field! Solution - make it a
        property and invoke Dog.Whine() in the setter. :))


        "Dave Quigley[work]" <dave at outta-sites dot com> wrote in message
        news:enPw2qZbDH A.4020@tk2msftn gp13.phx.gbl...[color=blue]
        > This is what seems wierd to me. If yo have a private set property why even
        > have it at all. why not just use the member variable. your basically[/color]
        sayign[color=blue]
        > i need to access a member in a class from within the same class but not
        > anywhere else. It seems a waste to me to write methods and properties for
        > something like this.
        > "Val Savvateev" <vsavvateev@mer idium.com_NO_SP AM> wrote in message
        > news:eBognQZbDH A.3080@TK2MSFTN GP11.phx.gbl...[color=green]
        > > Nope. Create a private method instead of setter.
        > >
        > > "Ben R. Bolton" <xbridgehd@hotm ail.com> wrote in message
        > > news:OL7buGZbDH A.3080@TK2MSFTN GP11.phx.gbl...[color=darkred]
        > > > Is it possible to define a property such that the get accessor is[/color][/color][/color]
        public[color=blue][color=green]
        > > and[color=darkred]
        > > > the set accessor is private?
        > > >
        > > > Ben
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...