This is really more of an academic question, but where is this function defined? Within .NET, I’m used to working in an object oriented manner. However, if I define a VB.NET class as follows:
Public Class foo
Public Sub showmessagebox()
Dim i As Integer
i = MsgBox("Message")
End Sub
End Class
Is MsgBox defined in a class? I am not required to reference a static class or inherit from another class. I’m not even required to import a namespace. I did find this link from msdn. But my question remains, where is this defined and how does the CLR just load up a function?
If you enter
MsgBoxinto Visual Studio and hit F12, you will see that it is in theMicrosoft.VisualBasicnamespace, in theInteractionmodule.In fact, this information is also available (although a bit hidden) at the bottom of the MSDN page you referenced:
If you look into the
Referencessection of your project properties, you’ll see that theMicrosoft.VisualBasicnamespace is automatically imported. SinceInteractionis a module, you can use its methods without having to qualify the module name (as opposed to static/Shared methods of a class).As a side note: If you add a reference to Microsoft.VisualBasic.dll to a C# project, you can use
Microsoft.VisualBasic.Interaction.MsgBox("Hello World");there as well (although most C# users will prefer using theMessageBoxclass).