| re: Class vs Structure Vs Module in Visual Basic .Net
A module is the same as a Public Static Class in C# (Public NotInheritable Class in VB). Cosmetically you don't have to specify the class name to reference its methods like you do with a Public Static Class. In a module, members by default are public and as such a variable can be seen across the global scope of your application. In a class you normally have to reference variables and other members by the fully qualified path name, i.e. instance.member, however, if you use imports MyNamespace.MyModule in VB or using MyNamespace.MyClass in C# then you can access the member directly just as if it were in a module... as long as the member is declared as shared in VB or static within C#.
If you do some digging into the underlying IL, you will see that both modules and static classes are implemented in the same way, so really - modules and static classes are the same, any differences are purely cosmetic.
Of course, there's always some caveats: The keyword Module can only be used directly within a namespace, you cannot nest modules... however, you can nest static/notinheritable classes. So while under the covers they're the same, syntactically, one is not allowed.
A module cannot inherit or implement anything... it can contain subclasses
At first glance a structure is similar to a class in many ways, one noticeable way that it's different is that it's passed ByVal instead of ByRef between methods - unless you explicitly state that it must be passed ByRef. Structs perform better due to heap/stack management differences because structs are stored on the stack whereas classes are stored on a heap. When a struct stores small amounts of data, it is stored in memory more efficiently than a class.
|