473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Class vs Structure Vs Module in Visual Basic .Net

110 100+
I was quickly curious what the difference between a class, a structure, and a module is in Visual Basic .Net in relation to C++.

Is a Structure truly a struct like in C, or is it essentially a class with all members defaultly public? And what is the point of a Module (I used one back in the day with VB6, but have read they have major speed issues--and why are they inefficient?).

How do these three fit in with each other in relation to Polymorphism? Can I inherit a Module from a Class or vs versa?

I've found it's quite hard to find documentation in MSDN on things like this, and googling hasn't gotten me far. And I hate to start up a new thread on such a fundamental/easy question...

I am basically interested in knowing features one may have over another. And if anyone knows of how to do a Union like in C/C++, I would be greatly appreciative to know how.

Hopefully Helpful,

TamusJRoyce
Nov 24 '08 #1
1 4579
balabaster
797 Expert 512MB
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.
Nov 24 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Edvard Majakari | last post by:
Hi, I just found py.test and converted a large unit test module to py.test format (which is actually almost-no-format-at-all, but I won't get there now). Having 348 test cases in the module and...
4
by: clintonG | last post by:
I'd like to know about application(s) or the name by which the following process is referred which would allow a business analyst to enter the following statements which when submitted would result...
5
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but...
3
by: Zahid | last post by:
Hi, I have declared an array holding a custom declared structure. The structure looks like this: Private Structure MnuDataFrmFile Public menuGroup As String Public ItemDesc As String Public...
4
by: http://www.visual-basic-data-mining.net/forum | last post by:
Hi Does anyone know how to stay connected to the server and at the same time i can pass the string to and from the module to the form..... What I want: I put the connection at the...
29
by: Michael D. Ober | last post by:
Is there any way to create a constant in a class that can be used both with an instantiated object and without. For example: dim ClassConst as string = myClass.ConstantString dim myObj = new...
36
by: Cap'n Ahab | last post by:
I have used VB3 - VB6, so learning all this OO stuff is reasonably new to me (although I looked at Java a few years ago). Anyway, I thought I would write a small class to begin with, with a...
13
by: André | last post by:
Hi, i'm developping asp.net applications and therefore i use VB.net. I have some questions about best practises. According what i read about class and module and if i understand it right, a...
13
by: Hussein B | last post by:
Hi, I'm familiar with static method concept, but what is the class method? how it does differ from static method? when to use it? -- class M: def method(cls, x): pass method =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.