Property question

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

    Property question

    Is it possible to have a property with its GET to public and its SET to
    private or friend?

    or vice versa


  • Theo Verweij

    #2
    Re: Property question

    This was possible in VB6, but as far as I know not in .Net

    But, you can simulate it like this:

    Private fStorageField as string

    Public Readonly Propery StorageField() As String
    Get
    Return fStorageField
    End Get
    End Property

    Private, you use fStorageField (which is RW), and public you use
    Storagefield (Which is RO)

    Or, the other way around:
    Private fStorageField as string

    Public Writeonly Propery StorageField() As String
    Set(ByVal value as string)
    fStorageField = value
    End Get
    End Property

    Private, you use fStorageField (which is RW), and public you use
    Storagefield (Which is WO)

    Instead of private, you can also use Friend.



    Pedro wrote:
    Is it possible to have a property with its GET to public and its SET to
    private or friend?
    >
    or vice versa
    >
    >

    Comment

    • Göran Andersson

      #3
      Re: Property question

      Pedro wrote:
      Is it possible to have a property with its GET to public and its SET to
      private or friend?
      >
      or vice versa
      >
      >
      Yes. Example from MSDN:

      public string Name
      {
      get
      {
      return name;
      }
      protected set
      {
      name = value;
      }
      }

      Comment

      • Theo Verweij

        #4
        Re: Property question

        Yust learned something today!
        It works also in VB!

        Göran Andersson wrote:
        Pedro wrote:
        >Is it possible to have a property with its GET to public and its SET
        >to private or friend?
        >>
        >or vice versa
        >>
        >>
        Yes. Example from MSDN:

        public string Name
        {
        get
        {
        return name;
        }
        protected set
        {
        name = value;
        }
        }

        Comment

        • Göran Andersson

          #5
          Re: Property question

          Right. Sorry about posting C# code in the VB forum.

          Theo Verweij wrote:
          Yust learned something today!
          It works also in VB!
          >
          Göran Andersson wrote:
          >Pedro wrote:
          >>Is it possible to have a property with its GET to public and its SET
          >>to private or friend?
          >>>
          >>or vice versa
          >>>
          >>>
          >>
          >Yes. Example from MSDN:
          >>
          >public string Name
          >{
          > get
          > {
          > return name;
          > }
          > protected set
          > {
          > name = value;
          > }
          >}
          >

          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Property question

            "Theo Verweij" <tverweij@xs4al l.nlschrieb:
            This was possible in VB6, but as far as I know not in .Net
            It's possible in VB 2005 again!

            --
            M S Herfried K. Wagner
            M V P <URL:http://dotnet.mvps.org/>
            V B <URL:http://classicvb.org/petition/>

            Comment

            • Michel Posseth  [MCP]

              #7
              Re: Property question

              It's possible in VB 2005 again!
              And again we saw a feature that was already known in VB6 return to VB.net
              :-)


              regards

              Michel Posseth [MCP]


              "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atschr eef in bericht
              news:%23DEM9D4o GHA.504@TK2MSFT NGP05.phx.gbl.. .
              "Theo Verweij" <tverweij@xs4al l.nlschrieb:
              >This was possible in VB6, but as far as I know not in .Net
              >
              It's possible in VB 2005 again!
              >
              --
              M S Herfried K. Wagner
              M V P <URL:http://dotnet.mvps.org/>
              V B <URL:http://classicvb.org/petition/>

              Comment

              • Theo Verweij

                #8
                Re: Property question

                And thats why I waited till VB2005 before I went away from VB6 ;-)

                Michel Posseth [MCP] wrote:
                >It's possible in VB 2005 again!
                >
                And again we saw a feature that was already known in VB6 return to VB.net
                :-)
                >
                >
                regards
                >
                Michel Posseth [MCP]
                >
                >
                "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atschr eef in bericht
                news:%23DEM9D4o GHA.504@TK2MSFT NGP05.phx.gbl.. .
                >"Theo Verweij" <tverweij@xs4al l.nlschrieb:
                >>This was possible in VB6, but as far as I know not in .Net
                >It's possible in VB 2005 again!
                >>
                >--
                >M S Herfried K. Wagner
                >M V P <URL:http://dotnet.mvps.org/>
                >V B <URL:http://classicvb.org/petition/>
                >
                >

                Comment

                Working...