본문 바로가기
Visual Basic .NET/Class

using MyBase

by edupicker(체르니) 2008. 6. 25.
Hello, everyone.
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
사용자 삽입 이미지