cannot set property value in a structure using Me

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

    cannot set property value in a structure using Me

    Does any one know why the following code works the way? and in C# it works in a different way what is the meaning of "Me" in VB.NET and why is it different than in C#

    Structure Test
    Private mName As String

    Property Name() As String
    Get
    Return Me.mName
    End Get
    Set(ByVal Value As String)
    Me.mName = Value
    End Set
    End Property

    Sub foo(ByVal s As String)
    Me.Name = s 'this line fails
    Name = s 'this line does not fail
    End Sub

    End Structure

    C# code
    struct Test
    {
    string mName;

    public string Name
    {
    get
    {
    return this.mName;
    }
    set
    {
    this.mName = value;
    }
    }

    public void foo(string s)
    {
    this.Name = s; //no error
    }
    }

  • Think_Fast

    #2
    Re: cannot set property value in a structure using Me

    I don't know why it doesn't work using Me that way. But I found that this seems to work.

    Public Sub foo(ByVal s As String)
    Dim r As String
    r = (Me.Name = s).ToString
    Name = s 'this line does not fail
    End Sub

    "Sankar Nemani" <snemani@nospam lumedx.com> wrote in message news:%23Ow%23ht EnEHA.2948@TK2M SFTNGP11.phx.gb l...
    Does any one know why the following code works the way? and in C# it works in a different way what is the meaning of "Me" in VB.NET and why is it different than in C#

    Structure Test
    Private mName As String

    Property Name() As String
    Get
    Return Me.mName
    End Get
    Set(ByVal Value As String)
    Me.mName = Value
    End Set
    End Property

    Sub foo(ByVal s As String)
    Me.Name = s 'this line fails
    Name = s 'this line does not fail
    End Sub

    End Structure

    C# code
    struct Test
    {
    string mName;

    public string Name
    {
    get
    {
    return this.mName;
    }
    set
    {
    this.mName = value;
    }
    }

    public void foo(string s)
    {
    this.Name = s; //no error
    }
    }

    Comment

    • Peter Huang

      #3
      RE: cannot set property value in a structure using Me

      Hi Sankar,

      This is a known issue and the product group is planning to fix the problem
      in the next version of .net framework but I can not guarantee if that will
      be done.
      Here is a KB, you may take a look.
      BUG: You Cannot Use the Me Keyword Before the Property Name in a Microsoft
      Visual Basic .NET Structure (819354)


      Best regards,

      Peter Huang
      Microsoft Online Partner Support

      Get Secure! - www.microsoft.com/security
      This posting is provided "AS IS" with no warranties, and confers no rights.

      Comment

      • Sankar Nemani

        #4
        Re: cannot set property value in a structure using Me

        That helps.
        Thanks
        Sankar
        ""Peter Huang"" <v-phuang@online.m icrosoft.com> wrote in message
        news:vNDcswFnEH A.2100@cpmsftng xa06.phx.gbl...[color=blue]
        > Hi Sankar,
        >
        > This is a known issue and the product group is planning to fix the problem
        > in the next version of .net framework but I can not guarantee if that will
        > be done.
        > Here is a KB, you may take a look.
        > BUG: You Cannot Use the Me Keyword Before the Property Name in a Microsoft
        > Visual Basic .NET Structure (819354)
        > http://support.microsoft.com/default...B;EN-US;819354
        >
        > Best regards,
        >
        > Peter Huang
        > Microsoft Online Partner Support
        >
        > Get Secure! - www.microsoft.com/security
        > This posting is provided "AS IS" with no warranties, and confers no[/color]
        rights.[color=blue]
        >[/color]


        Comment

        • Peter Huang

          #5
          Re: cannot set property value in a structure using Me

          Hi Sankar,

          You are welcome, I am glad my reply is of help.
          Cheers!

          Best regards,

          Peter Huang
          Microsoft Online Partner Support

          Get Secure! - www.microsoft.com/security
          This posting is provided "AS IS" with no warranties, and confers no rights.

          Comment

          Working...