Can someone explain the difference between a class and a module. When do you use one versus the other? I am using C#.
Update: I do mean the C# equivalent of the VB Module.
This depends heavily on which "Module" you are referring to.
There is no real equivalent in C# for a VB.Net Module. In ways it's similar to a static class in that you cannot create an instance of it and all of the members inside of it are static. In C# this requires an explicit static keyword while in VB.Net it's implicit.
The big difference though is in name lookup. In VB.Net if a Module is in scope then any of it's methods can be called without qualification. This is not true for C# static classes.
Besides name lookup, the primary difference between a class and a module is that a class is typically useful only with an instance of the type.
A module in this context is a portable executable file (dll or exe). A given DLL/EXE can be composed of several modules if it's a multi-file assembly. It has no real relationship to an individual class.
(Maybe I should be clear, there are no "Modules" in C# as in VB.NET's "Module")
There are no modules in C# (like the modules in VB or VB.NET). So, instead a module is one which is compiled and packaged into an assembly, it's more logical.
Whereas class is a well defined entity. A module may use a class (or classes), to function. (Again the word "module" is used logically)
The word "Module" is also used in a context quite different, in System.Reflection.Module
A module is a compiled dll or exe, it contains the compiled classes. A class is the same as a class in most any other language.
Also, modules, whether it's one or more are what make up Assemblies in .Net
Remember that once it's compiled in .Net it doesn't matter what language it was written in, it's all IL, so the terms you're describing are pretty much language agnostic at that point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With