December 2001
Beginner
976 pages
22h 4m
English
In code, you can frequently encounter a case where an object must be created and immediately after its properties must be set to a set of values. For example, if you continue with the Horse class:
Module Module1
Sub Main()
Dim h As Horse = New Horse()
h.m_name = "Lightning"
h.m_color = "Brown"
h.m_height = 1.9
Console.Out.WriteLine("Name is {0} ", h.m_name)
Console.Out.WriteLine("Color is {0} ", h.m_color)
Console.Out.WriteLine("Height is {0} ", h.m_height)
End Sub
End Module
The example is pretty common: Create an object and set the values for its fields. This task can become tedious, especially for classes with a large number of fields. That is one of the reasons why class constructors (or constructors, in short) were introduced ...
Read now
Unlock full access