VB.Net Tutorial/Class Module/Me

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

Demonstrates Me reference

<source lang="vbnet">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</source>

12:30:19

Use Me to reference myself

<source lang="vbnet">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</source>