Not a duplicate of "Access of shared member, constant member, enum member or nested type through an instance"
VB.NET has a warning message
(BC42025): "Access of shared member through an instance; qualifying expression will not be evaluated" as documented
here.
I take the meaning of the phrase "Access of shared member through an instance" as: your code declared a Dog
object name Fido
, and then called Fido.Bark()
, but in the Dog
class, the Bark
function is declared with the Shared
keyword.
But I don't know what the second part of that message mean. I always thought it sounded like it was saying that VB would just skip over that line of code, but that's not true.
The documentation explain the phrase as:
Furthermore, if such access is part of an expression that performs other actions, such as a
Function
procedure that returns an instance of the shared member, Visual Basic bypasses the expression and any other actions it would otherwise perform.
But I cannot tell what that means, what is it that Visual Basic is bypassing? Can you explain it in code?
Code for context
Sub Main
Dim dog1 As Dog = New Dog()
dog1.Bark() ' this line has the warning
End Sub
Public Class Dog
Public Shared Sub Bark()
End Sub
End Class
EDIT
I understand that the compiler wants me to access static methods via the Class name, what I want to understand is what does it mean that "Visual Basic bypasses the expression and any other actions it would otherwise perform." What are some possible "other actions" that could by bypassed ?