how about using Multiple Constructors to Support Different Parameters
how about using Multiple Constructors to Support Different Parameters
To initialize class member variables, programmers make extensive use of constructor methods.
Normally, for a simple class, the constructor method will support a parameter for each key class member variable.
Consider the following Book class that provides support for the title, author,
publisher, price, pagecount, and Indate:
source code :
class book
Public Publisher As String
Public Author As String
Public Price As Double
Public PageCount As Integer
Public InDate As String
Me.Title = Title
Me.Price = Price
Me.Author = ""
Me.PageCount = 0
Me.Publisher = ""
Me.InDate = ""
End Sub
ByVal Publisher As String, ByVal Price As Double)
Me.Title = Title
Me.Author = Author
Me.Publisher = Publisher
Me.Price = Price
Me.PageCount = 0
Me.InDate = ""
End Sub
ByVal Publisher As String, ByVal Price As Double, _
ByVal PageCount As Integer, ByVal InDate As Date)
Me.Title = Title
Me.Author = Author
Me.Publisher = Publisher
Me.Price = Price
Me.PageCount = PageCount
Me.InDate = InDate
End Sub
.......
Sub Main()
Dim ProgBook = New Book("VB.NET", "James Bond", "Prentice Hall", 39.5)
Dim EconoBook = New Book("social networking", _
"Gildong,Hong", "Yangji", 12.59, 256, "2008-02-01")
Console.WriteLine()
Console.WriteLine()
Console.ReadLine()
execution :