Иллюстрированный самоучитель по VB.NET



Перегрузка членов класса - часть 2


Console. WhteLine()

Dim Sally As New Employee("Sally", 150000)

Console.WriteLine(Sally.TheName & " has salary " & Sally.Salary)

Sally.RaiseSalary(0.2D,"special")

' Суффикс D - признак типа Decimal

Console.WriteLine(Sally.TheName & "has salary "SSally.Salary)

Console. WriteLine()

Console.WriteLine("Please press the Enter key")

Console. ReadLine()

End Sub

End Module

Public Class Employee

Private m_Name As String

Private m_Salary As Decimal

Private Const LIMIT As Decimal = 0.1D

Public Sub New(ByVal theName As String,ByVal curSalary As Decimal)

m_Name = thename

m_Salary = curSalary

End Sub

Readonly Property TheName()As String Get

Return m_Name

End Get '

End Property

Readonly Property Salary()As Decimal Get

Return m_Salary

End Get

End Property

Public Overloads

Sub RaiseSalary(ByVal Percent As Decimal)

If Percent > LIMIT Then

' Операция запрещена - необходим пароль

Console.WriteLine("MUST HAVE PASSWORD TO RAISE SALARY " & _

"MORE THAN LIMIT!!!!")

Else

m_Salary =(1 +Percent)*m_salary End If End Sub

Public Overloads

Sub RaiseSalary(ByVal Percent As Decimal._

ByVal Password As String)

If Password = "special" Then

m_Salary =(1 + Percent) * m_Salary

End If

End Sub

End Class




Содержание  Назад  Вперед