overload constructors

  • Thread starter Thread starter portroe
  • Start date Start date
do you mean something like this? (or a class that inherits and then
overloads?)

Public Class clsColli
Private colID As Integer
Private colNaam As String
Private colPrijs As Double
Private colOms As String

Public Sub New()
colID = 0
colNaam = ""
colOms = ""
colPrijs = 0
End Sub

Public Sub New(ByVal id As Integer)
Me.New()
colID = id

End Sub

Public Sub New(ByVal naam As String, Optional ByVal oms As String = "",
Optional ByVal prijs As Double = 0)
colID = 0
colNaam = naam
colOms = oms
colPrijs = prijs
End Sub
end class
 
* portroe said:
How do you overload constructors in VB .net?

\\\
Public Sub New()
...
End Sub

Public Sub New(ByVal Name As String)
...
End Sub
..
..
..
///
 
'my constructor looks like this

Public Sub New(ByVal title As String, ByVal qualification As String,
ByVal age As Integer)

Me.iTitle = title
Me.iQualification = qualification
Me.iAge = age

End Sub

' I want to implement multiple constructor overloads under this

thanks
 
then you can do as i said :)
you yust have to keep in mind you can't have 2 constructors w the same type
of parameters

ex.

public sub new(x as integer, y as string)
xke= x
yke= y
end sub
public sub new(x as integer, z as string) ' will give an error, you are
passing an integer and a string 2 times the program won't know w one you
mean
xke= x
zke= y
end sub

'you can do this
public sub new(z as string, x as integer)
xke= x
zke= y
end sub
 
'Overloaded ' ***** Signatures must be different

Public Sub New( ByVal title As String, ByVal qualification As String) '
only two parameters

End Sub

'AND

Public Sub New( ByVal title As String ) ' only one parameters

End Sub

'AND

Public Sub New( ) ' Zero parameters

End Sub


Now your Constructor can be any of the above.

*** Note - here you are overloading constructors. Dont forget, if you
override a constructor, remember to call MyBase.New() from the overridden
constrcutor.

Regards - OHM







'my constructor looks like this

Public Sub New(ByVal title As String, ByVal qualification As String,
ByVal age As Integer)

Me.iTitle = title
Me.iQualification = qualification
Me.iAge = age

End Sub

' I want to implement multiple constructor overloads under this

thanks

Best Regards - OHMBest Regards - OHM (e-mail address removed)
 
* portroe said:
'my constructor looks like this

Public Sub New(ByVal title As String, ByVal qualification As String,
ByVal age As Integer)


Me.iTitle = title
Me.iQualification = qualification
Me.iAge = age

End Sub

' I want to implement multiple constructor overloads under this

What's the problem? Notice that the different overloads must have a
different signature (number of parameters, type of parameters).
 
Back
Top