cannot set property value in a structure using Me

  • Thread starter Thread starter Sankar Nemani
  • Start date Start date
S

Sankar Nemani

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
}
}
 
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

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
}
}
 
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.aspx?scid=KB;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 rights.
 
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.
 
Back
Top