ASP.Net/Language Basics/Overload

Материал из .Net Framework эксперт
Версия от 11:53, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Define Overloads method

<%@ page language="vb" runat="server" %>
<script runat="server">
Public Class Car
  Private _Color As String
  Private _Gear As Integer
  Public Property Color As String
    Get
      Return _Color
    End Get
    Set
      _Color = value
    End Set
  End Property
  Public ReadOnly Property Gear As Integer
    Get
      Return _Gear
    End Get
  End Property
   Overloads Public Sub ChangeGear(direction As String)
    If direction = "down" Then ChangeGear(-1)
    If direction = "up" Then ChangeGear(+1)
  End Sub
  Sub New()
    _color = "cold grey steel"
  End Sub
End Class
Sub Page_Load()
  Dim MyCar As New Car()
  Response.Write("<b>New object "MyCar" created.</b>")
  Response.Write("<br/>Color: " & MyCar.Color)
  Response.Write("<br/>Gear: " & MyCar.Gear)
  MyCar.Color = "Black"
  MyCar.ChangeGear(+1)
  Response.Write("<br/><b>Properties updated.</b>")
  Response.Write("<br/>New color: " & MyCar.Color)
  Response.Write("<br/>New gear: " & MyCar.Gear)
  MyCar.ChangeGear("up")
  Response.Write("<br/><b>Shifted "up" one gear.</b>")
  Response.Write("<br/>New gear: " & MyCar.Gear)

End Sub
</script>