Reputation: 8031
I've been researching this, but i wanted some input from the community in regards to the MessageBox class
provided in VB.NET.
From my point of view and current understanding, i see MessageBox
as a Class
, mainly because in VS2010 shows it as a class. I see that we have methods within this class and properties. How come many websites, tutorials, books call this a Function?? Even MSDN calls it the MessageBox
function. Is it simply because this is part of the WINAPI?
Another question that arises now that i look at the MessageBox class in VB.NET a bit closer, how come we don't have to create an object of type Messagebox prior to using it. It appears that we can just call the Messagebox class and bring up the "Show"method...
I'm still in the beginner stages of fully understanding the OOP Concept and i wouldn't mind technical explanations in regards to this particular topic.
I was reading over the MSDN page for the MessageBox Function which is what originally triggered me to asked this question.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx
In Conclusion, my question: Why is "MessageBox" considered a function in VB.NET when VS2010 intellisense shows it as a Class?
Upvotes: 0
Views: 3504
Reputation: 941635
It isn't much of a class in the traditional sense of the word. It stores no state at all, it doesn't have any properties. Just methods, they are all Shared.
Which is more typically handled in VB.NET with a Module. But that's a highly specific VB.NET feature, this class is part of the framework and usable by any language. So it is only a class because the CLR requires that methods are part of a class.
You can still use the MsgBox() function. Inherited from VB6, does the same thing as MessageBox and is available in the global namespace. Just like a Function in a Module.
Upvotes: 3
Reputation: 7892
The page you reference is not referencing the MessageBox class of .NET framework, it references the MessageBox function of the windows api. These are two different things, even if they have the same name and deal with the same sort of thing. In fact I wouldn't be surprised if the static method Show of the MessageBox class of .NET internally marshalls a call to the MessageBox function of the windows api.
As for the second bit, you can call MessageBox.Show because the show method is a static, meaning you don't need an instance of the class to call it.
Upvotes: 2
Reputation: 24403
First of all MessageBox .net class is different from MessageBox Win32 API function.
The MessageBox class in .net only has meaningfull static methods that allow you to display a message to the user. And to call a static method of a class you don't need to create an instance.
Also nobody considers MessageBox .NET as a function they only consider MessageBox.Show method as a function. Are you confusing it to MsgBox in Visual Basic which was indeed a function
Upvotes: 1
Reputation: 1500835
You're looking at different contexts. In "normal" .NET it's a class - System.Windows.Forms.MessageBox
.
The document referred to was about a native MessageBox
function, defined in User32.dll. It's entirely separate.
Of course, there could also be MessageBox
methods declared in some .NET type or other. Basically, it's entirely legitimate for the same (unqualified) name to mean different things in different contexts.
Upvotes: 4