Global "Module" in C# similar to VB.NET's Module
I've been searching around here and elsewhere for an answer to this, but I
haven't found an exact answer.
I'm fairly new to C#. In VB.NET, you can define a Module, like a class,
which has some limitations and also some benefits. One of its great
benefits is that you can access all of its members globally if you've
imported the namespace (i.e. "using" in c#). For example:
Private Sub Test()
MsgBox(Now)
End Sub
In the method above, MsgBox is a method in the
Microsoft.VisualBasic.Interaction module and Now is a property in the
Microsoft.VisualBasic.DateAndTime module. I don't have to qualify the call
to either of them in order to use them, although I could:
Private Sub Test()
Microsoft.VisualBasic.Interaction.MsgBox(Microsoft.VisualBasic.DateAndTime.Now)
End Sub
I use this feature all the time in my own projects by building my own
modules with utility methods and properties. It's very, very useful. Is
there an equivalent in C#?
No comments:
Post a Comment