VB.Net form non-shared methods referenced as if they were shared?
vb.net, winforms
Solution
VB.NET has the (very nice) feature of keeping a collection of all forms as properties under the `My.Forms` object. The objects there are instantiated when you first access them. In this way, you get a default instance of each form that you can refer to.
On the not so nice side, VB insists on importing the `My.Forms` object’s properties globally, and there’s nothing you can do to change that.
In other words, the class name of any form in your application doubles as a global instance of that form.
Problem
I am doing support on a VB.Net application although I am primarily a C# developer. I have encountered what I consider to be "strange" code, in that my C# mindset tells me that the code is wrong and shouldn't compile, yet it does. I did a Find all references on a particular form to see where it was being used and found references to the form where non-shred methods of the class were being directly referenced without the class being instantiated. In other words, I see code like this: ``` FrmCareer.ShowDialog(careerId) FrmCareer = Nothing ``` Now ShowDialog is not a shared member, and it references instance member variables, so I would not expect intellisense to list the ShowDialog method at all. But it does and it compiles. Can anyone explain what is going on here?