IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesVB.Net    Print This   

Constructor (VB.Net and C++ Cross Reference Guide)

By Mike Prestwood

VB.Net versus C++: A side by side comparison between VB.Net and C++.

 
OOP Details
 

More object oriented (OO) stuff.

Constructor

[Other Languages] 

General Info: Class Constructor

Constructors are called when you instantiate an object from a class. This is where you can initialize variables and put code you wish executed each time the class is created. When you initially set the member fields and properties of an object, you are initializing the state of the object. The state of an object is the values of all it's member fields and properties at a given time.

Languages Focus

What is the syntax? Can you overload constructors? Is a special method name reserved for constructors?

VB.Net:  "Constructors" New

In VB.Net, a constructor is called whenever a class or struct is created. A constructor is a sub named New. You can overload the constructor simply by adding two or more New subs with various parameters (overloaded constructors).

If you do not create a constructor, VB.Net will create an implicit constructor that initializes all member fields to their default values.

Constructors can execute at two different times. Static constructors are executed by the CLR before any objects are instantiated. Regular constructors are executed when you create an object.

You can invoke the parent constructor with MyBase.New.

Syntax Example:
Public Class Cyborg
Public CyborgName As String
  
  Public Sub New(ByVal pName As String)
CyborgName = pName
End Sub
End Class
C++:  "Constructors" Use Class name

A member function with the same name as the class.

Syntax Example:  
class X {
public:
X(); // constructor for class X
};












-
  Load Time=1 seconds.
 
Print This
-
 
Have a question? Need our services? Contact us now.
--Mike Prestwood

Call: 916-726-5675

email: info@prestwood.com


-
 
Connect With Us...
PrestwoodBoards
Join Us!
Facebook
Like our page!!!
Twitter
Follow us!
LinkedIn
Join Group
YouTube
View channel.
Go ahead!   Use Us! Call: 916-726-5675 


©1995-2014 Prestwood IT Solutions.   [Security & Privacy]   Made in the U.S.A..   No H1-B.   No offshoring.