Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 1

class and objects in vb.

net:
http://msconline.maconstate.edu/tutorials/vbnet/default.htm ---for data types,function
structures and classes differ in the following particulars:

structures are value types; classes are reference types. a variable of a structure type contains the
structure's data, rather than containing a reference to the data as a class type does.

structures use stack allocation; classes use heap allocation.

all structure elements are public by default; class variables and constants are private by default, while
other class members are public by default. this behavior for class members provides compatibility with
the visual basic 6.0 system of defaults.

a structure must have at least one nonshared variable or nonshared, noncustom event element; a class
can be completely empty.

structure elements cannot be declared as protected; class members can.

a structure procedure can handle events only if it is a shared (visual basic) sub procedure, and only by
means of the addhandler statement; any class procedure can handle events, using either the handles
keyword or the addhandler statement. for more information, see events and event handlers.

structure variable declarations cannot specify initializers or initial sizes for arrays; class variable
declarations can.

structures implicitly inherit from the system.valuetype class and cannot inherit from any other type;
classes can inherit from any class or classes other than system.valuetype.

structures are not inheritable; classes are.

structures are never terminated, so the common language runtime (clr) never calls the finalize method
on any structure; classes are terminated by the garbage collector (gc), which calls finalize on a class
when it detects there are no active references remaining.

a structure does not require a constructor; a class does.

structures can have nonshared constructors only if they take parameters; classes can have them with or
without parameters.

every structure has an implicit public constructor without parameters. this constructor initializes all the
structure's data elements to their default values. you cannot redefine this behavior.

You might also like