VB.Net Tutorial/Class Module/Me — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:55, 26 мая 2010

Demonstrates Me reference

Module Tester
   Sub Main()
      Dim time As New MyTime(12, 30, 19)
      Console.WriteLine(time.ToUniversalString())
   End Sub " Main
End Module

Class MyTime
   Private mHour, mMinute, mSecond As Integer
   Public Sub New(ByVal mHour As Integer, _
      ByVal mMinute As Integer, ByVal mSecond As Integer)
      Me.mHour = mHour
      Me.mMinute = mMinute
      Me.mSecond = mSecond
   End Sub " New
   Public Function ToUniversalString() As String
      Return String.Format("{0:D2}:{1:D2}:{2:D2}", _
         mHour, mMinute, mSecond)
   End Function " ToUniversalString
End Class
12:30:19

Use Me to reference myself

Option Strict On
 Imports System
 Public Class Time
    Private Second As Integer
    Public Sub DisplayCurrentTime( )
       System.Console.WriteLine(Second)
    End Sub
    Public Sub New(ByVal dt As System.DateTime)
       Second = dt.Second
    End Sub 
    Public Sub New(ByVal Second As Integer)
       Me.Second = Second
    End Sub
 End Class 
 Module Module1
    Sub Main( )
       Dim currentTime as System.DateTime = System.DateTime.Now
       Dim time1 As New Time(currentTime)
       time1.DisplayCurrentTime( )
       Dim time2 As New Time(30)
       time2.DisplayCurrentTime( )
    End Sub
 End Module