Trying to find out what is essential / optional, I made an extremely simple
Class and Module combination to add two numbers. (see below)
It appears that an empty constructor is needed n order to work right,
although I quite don't see what is does in addition to the 2nd constructor.
Also, the example works fine without message calls in either constructor
(the numerical answer is still there and correct!).
I exected it to no longer work and return build or run errors.
Please explain,
Thanks for your help,
John
***************
Public Class CSum
Public mSum As Integer
Public Sub New()
'Sum(0, 0)
End Sub
Public Sub New(ByVal firstNumber As Integer, ByVal lastNumber As Integer)
'Sum(firstNumbe r, lastNumber)
End Sub
Public Sub Sum(ByVal firstNumber As Integer, ByVal lastNumber As Integer)
mSum = firstNumber + lastNumber
End Sub
End Class
Module Module1
Sub Main()
Dim thisFirstNumber As Integer = 10
Dim thisLastNumber As Integer = 100
Dim thisSum As New CSum
thisSum.Sum(thi sFirstNumber, thisLastNumber)
Console.WriteLi ne("The sum of {0} and {1} = {2}", _
thisFirstNumber , thisLastNumber, thisSum.mSum)
End Sub
End Module
Class and Module combination to add two numbers. (see below)
It appears that an empty constructor is needed n order to work right,
although I quite don't see what is does in addition to the 2nd constructor.
Also, the example works fine without message calls in either constructor
(the numerical answer is still there and correct!).
I exected it to no longer work and return build or run errors.
Please explain,
Thanks for your help,
John
***************
Public Class CSum
Public mSum As Integer
Public Sub New()
'Sum(0, 0)
End Sub
Public Sub New(ByVal firstNumber As Integer, ByVal lastNumber As Integer)
'Sum(firstNumbe r, lastNumber)
End Sub
Public Sub Sum(ByVal firstNumber As Integer, ByVal lastNumber As Integer)
mSum = firstNumber + lastNumber
End Sub
End Class
Module Module1
Sub Main()
Dim thisFirstNumber As Integer = 10
Dim thisLastNumber As Integer = 100
Dim thisSum As New CSum
thisSum.Sum(thi sFirstNumber, thisLastNumber)
Console.WriteLi ne("The sum of {0} and {1} = {2}", _
thisFirstNumber , thisLastNumber, thisSum.mSum)
End Sub
End Module
Comment