obiewoncanoli
New member
- Joined
- Jun 22, 2010
- Messages
- 1
- Programming Experience
- 10+
re: Access of shared member constant member enum member or nested type through an instance qualifying expression may not be evaluated
I understand that this warning means that you should not reference a shared member via an instance. However, in my test case Test2.t.x("3"), I don't understand why it thinks I'm using an instance, since t is also a shared member.
Also, note Test3. See what happens when you change declaration of GetObject() As Object to As Test3. I think I understand the behavior (not eval'd until runtime), but I'd appreciate some thoughts/insights. Thanks.
Module Module1
Class Test1
Public Shared Sub x(ByVal s As String)
Console.WriteLine("test1 - " & s)
End Sub
End Class
Class Test2
Public Shared t As Test1
End Class
Public Class Test3
Public Sub New()
Console.WriteLine("New Test3")
End Sub
Public Shared NumCreations As Integer = 0
Public Shared Function GetObject() As Object 'As Test3
NumCreations += 1
Return New Test3
End Function
End Class
Sub Main()
Dim t As Test1
t.x("1")
Test1.x("2")
Test2.t.x("3")
Console.WriteLine(Test3.GetObject().NumCreations)
Console.ReadLine()
End Sub
End Module
I understand that this warning means that you should not reference a shared member via an instance. However, in my test case Test2.t.x("3"), I don't understand why it thinks I'm using an instance, since t is also a shared member.
Also, note Test3. See what happens when you change declaration of GetObject() As Object to As Test3. I think I understand the behavior (not eval'd until runtime), but I'd appreciate some thoughts/insights. Thanks.
Module Module1
Class Test1
Public Shared Sub x(ByVal s As String)
Console.WriteLine("test1 - " & s)
End Sub
End Class
Class Test2
Public Shared t As Test1
End Class
Public Class Test3
Public Sub New()
Console.WriteLine("New Test3")
End Sub
Public Shared NumCreations As Integer = 0
Public Shared Function GetObject() As Object 'As Test3
NumCreations += 1
Return New Test3
End Function
End Class
Sub Main()
Dim t As Test1
t.x("1")
Test1.x("2")
Test2.t.x("3")
Console.WriteLine(Test3.GetObject().NumCreations)
Console.ReadLine()
End Sub
End Module