Scott M. said:
I disagree with your interpretation of what's going on here. Regardless of
"inside out" processing. Passing a parameter does not
cause an instance of anything to be made as parameters either
receive a copy of data or a copy of a reference to an "already
existing" object. There is no instance being created by this code.
On one side, this is not true, on the other side, it does neither matter
whether an instance is created, nor whether an instance exists at all. The
statement is not true because Color is a value type and the object is passed
ByVal. This means, a copy of the object is created on the stack whenever the
parameter is passed. Thus, passing the object does create a new one.
But as just written, this does not matter. The only thing that is of
interest is to which identifier the name refers. It can either be a
- type name or
- the name of a variable.
Nothing else matters. There is no doubt that the first identifier found by
the compiler is the variable name.
The compile error message could be considered not being completely correct.
Instead of
"Access of shared member through an instance..."
it should be
"Access of shared member through an expression..."
The reason for this is that the variable can be of a reference type and it
points to Nothing. We don't have an instance then, though it can be compiled
and also executed without an error because the compiler is only interested
in the type of the variable in order to access the shared member of that
type. No instance access is done. So, I vote for correcting the error
message. ;-) On the other side, the code looks as if an instance member is
accessed. Maybe that's what the error message wants to tell us.
I wrote "expression", not "variable" because this is also possible:
Sub X()
MsgBox(y.AliceBlue.ToString)
End Sub
Function y() As Color
End Function
If I understood you right, you're saying that the parameter name is ignored
because the compiler is looking for a _type name_ called 'color', right? I
can even proof you that you are wrong:
Public Class Form1
Class Color
Public Shared test As Boolean
End Class
Sub x(ByVal Color As System.Drawing.Color)
Dim o As Color
Color.test = True
End Sub
End Class
First, variable 'o' is of my _own_ type color. That's the proof that name
resolution is done inside out. I think we agree in this point. BUT: If you
were right, the line "Color.test = true" should be compilable! You said that
the paramenter name is ignored. What does the compiler find next? It's my
own class Color. So, why does "Color.Test = true" does not work? It's
because the compiler is only interested in the type of the argument. If it
would ignore the argument name, it MUST be able to compile the code. The
compile error "test is not a member of 'system.drawing.color'" is absolutely
bullet proof.
Armin