virtualcalls.vb

来自「Microsoft Mobile Development Handbook的代码」· VB 代码 · 共 57 行

VB
57
字号
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Diagnostics
Imports System.Windows.Forms

Namespace CodeForChapter5cs
  Public Class [MyClass]
	Private myVar As Integer = 1
	Public Property MyProperty() As Integer
	  Get
		  Return myVar
	  End Get
	  Set(ByVal value As Integer)
		  myVar = value
	  End Set
	End Property

	Private myVVar As Integer = 1
	Public Overridable Property MyVirtualProperty() As Integer
	  Get
		  Return myVVar
	  End Get
	  Set(ByVal value As Integer)
		  myVVar = value
	  End Set
	End Property

	Public Sub Test1()
	  GC.Collect()
	  Dim sw As Stopwatch = Stopwatch.StartNew()
	  Dim total As Integer = 0
	  For i As Integer = 0 To 999999
		total += Me.MyProperty
	  Next i
	  sw.Stop()
	  Dim millis As Long = sw.ElapsedMilliseconds

	  MessageBox.Show(total.ToString(), millis.ToString())
	End Sub

	Public Sub Test2()
	  GC.Collect()
	  Dim sw As Stopwatch = Stopwatch.StartNew()
	  Dim total As Integer = 0
	  For i As Integer = 0 To 999999
		total += Me.MyVirtualProperty
	  Next i
	  sw.Stop()
	  Dim millis As Long = sw.ElapsedMilliseconds

	  MessageBox.Show(total.ToString(), millis.ToString())
	End Sub
  End Class
End Namespace

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?