Hello, everyone.
nice day, isn't it?
This time , I'll explain how to use MyBase Class.
nice day, isn't it?
This time , I'll explain how to use MyBase Class.
MyBase Provides a way to refer to the base class of the current class instance.
MyBase.New is used to explicitly call a base class constructor from a derived class constructor.
In the derived-class constructor, the call to the base-class constructor must be the first statement.
Otherwise, Visual Basic .NET will generate a syntax error when you try to compile your program. If the base-class constructor does not require parameters,
the derived class can omit the call to MyBase.New.
Visual Basic .NET, in turn, will automatically call the base-class constructor when the derived-class constructor starts.
However, to improve the readability of their code, many programmers will include
the following MyBase.New method call at the start of a derived-class constructor to remind other programmers (who may be reading the code) that the base class exists and that its constructor does execute.
The following program, creates a base class named Person that has
fields that store an individual’s first and last names. Within the Person class, the New method assigns the names it receives as parameters to the FirstName and LastName fields.
Next, the code derives the Programmer class from the Person class by adding a part and Lang.
Finally, I added the Streamwriter in order to store the result in a file which is located in "C:\temp" directory.
If you want to handle StreamWriter, you just imports system.IO.
class's source code :
execution :
1. Input data form
2. store in classlog.txt file
MyBase.New is used to explicitly call a base class constructor from a derived class constructor.
In the derived-class constructor, the call to the base-class constructor must be the first statement.
Otherwise, Visual Basic .NET will generate a syntax error when you try to compile your program. If the base-class constructor does not require parameters,
the derived class can omit the call to MyBase.New.
Visual Basic .NET, in turn, will automatically call the base-class constructor when the derived-class constructor starts.
However, to improve the readability of their code, many programmers will include
the following MyBase.New method call at the start of a derived-class constructor to remind other programmers (who may be reading the code) that the base class exists and that its constructor does execute.
The following program, creates a base class named Person that has
fields that store an individual’s first and last names. Within the Person class, the New method assigns the names it receives as parameters to the FirstName and LastName fields.
Next, the code derives the Programmer class from the Person class by adding a part and Lang.
Finally, I added the Streamwriter in order to store the result in a file which is located in "C:\temp" directory.
If you want to handle StreamWriter, you just imports system.IO.
class's source code :
execution :
1. Input data form
2. store in classlog.txt file
'Visual Basic .NET > Class' 카테고리의 다른 글
how to use overrides Keyword (0) | 2008.06.26 |
---|---|
A destructor method in a class (0) | 2008.06.26 |
understand the inherited constructors of class (0) | 2008.06.25 |
how about using Multiple Constructors to Support Different Parameters (0) | 2008.06.24 |
how to Initialize Class Member Variables (0) | 2008.06.24 |