What advantage is there, if any, to using Modules rather than classes in VB? How do they differ, and what advantages/disadvantages are there in using modules? In VB or VB.NET, I use both.
相关问题
- What uses more memory in c++? An 2 ints or 2 funct
- 'System.Threading.ThreadAbortException' in
- how to use special characters like '<'
- How Does WebSphere Choose the Classloading Order i
- C# to VB - How do I convert this anonymous method
相关文章
- vb.net 关于xps文件操作问题
- Checking for DBNull throws a StrongTypingException
- Using the typical get set properties in C#… with p
- NameError: name 'self' is not defined, eve
- Load a .NET assembly from the application's re
- C# equivalent of VB DLL function declaration (Inte
- What other neat tricks does the SpecialNameAttribu
- .NET - how to make a class such that only one othe
Module are come earlier and now VB.NET just let it for backward compatibility. Modules and Class are nearly same. You can call Module.Function() directly as it treat as
Shared
Function in a class. Class you can defineShared
Function/Method and additionally can create an instance likeDim c as Class = New Class()
.Avoid use of Module, instead use Class. it is good for you to write a better OOP programming.
(A) Modules
and
(B) Classes with only
Shared
functionssolve the same problem: Both allow you to logically group a set of functions.
Advantages of using a module:
Advantages of using a class with shared functions:
So, if you are writing a set of helper functions and want to logically group them (where the concept of a state of this group just doesn't make sense), use a module -- this is exactly what they are here for. On the other hand, if you have a function that conceptually fits to an already existing class, add it as a shared function to that class.
A major difference is that methods in modules can be called globally whereas methods in classes can't. So instead of
ModuleName.MyMethod()
you can just callMyMethod()
. Whether that is an advantage or disadvantage depends on the circumstances.