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 :
'Visual Basic .NET > Class' 카테고리의 다른 글
A destructor method in a class (0) | 2008.06.26 |
---|---|
using MyBase (0) | 2008.06.25 |
understand the inherited constructors of class (0) | 2008.06.25 |
how to Initialize Class Member Variables (0) | 2008.06.24 |
How to Restrict Access to Class Members? (0) | 2008.06.23 |