Application Wide Shared Methods

false74

Well-known member
Joined
Aug 4, 2010
Messages
76
Programming Experience
Beginner
I am developing an application that has multiple forms and I wanted to know the best method to have application wide methods and functions. Currently I am using a Module with all my methods that are needed to be used across the entire application in it.
However, I read at one point that modules should not be used, as they are only there to preserve backwards compatibility with older VB code. Is there a better way to have methods able to be called anywhere?
 
What you read is not true. Modules themselves are a VB-specific language construct but, once compiled, they become static classes, exactly the same as static classes in C#. I've never read anyone say that it is wrong to use static classes in C# so it is no less wrong to use modules in VB. People are fond of bashing anything that appears to be a hold-over from VB6 but modules serve a specific purpose in VB.NET. VB.NET syntax is based on VB6 syntax so it makes sense that modules are used rather than shared classes, while C# syntax is based on C/C++ syntax so static classes are natural.

That said, modules and static classes should not be used all that often. Only add functionality to a module if it is specifically appropriate, not just because it's convenient.
 
Back
Top