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.
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.
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.
(May be 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, its 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 class is an independent unit of data and functions - fields, properties, and methods.
A module refers to the code generated from a single physical file. Most of the time, when you write code in Visual Studio, a single file will contain a single class, interface, or struct.
Compiled DLLs or EXEs are called assemblies. An assembly can contain any number of modules as well as other resources such as version information. By default, when you compile an assembly in Visual Studio, the assembly contains every module defined in the project.
As for when you would use them: You use classes, interfaces and structs all the time, those are the basics. Modules are things that you generally don't have much control over; again, it's a generally accepted practice to have one type per file which compiles to one type per module.
You would normally use a separate assembly when you want to reuse certain types (contained within certain modules) across multiple projects. You might also use it to create a hard boundary between different components of an application, i.e. put your database logic in one assembly and your business logic in another.
There's no equivalent in C# to the VB6 module. The closest would be a static class, but even then, the members of the class are not global, as they would be in a VB6 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.