⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 virtualcalls.cs

📁 Microsoft Mobile Development Handbook的代码,有C#,VB,C++的
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;

namespace CodeForChapter5cs
{
  public class MyClass
  {
    private int myVar = 1;
    public int MyProperty
    {
      get { return myVar; }
      set { myVar = value; }
    }

    private int myVVar = 1;
    public virtual int MyVirtualProperty
    {
      get { return myVVar; }
      set { myVVar = value; }
    }

    public void Test1()
    {
      GC.Collect();
      Stopwatch sw = Stopwatch.StartNew();
      int total = 0;
      for (int i = 0; i < 1000000; i++)
      {
        total += this.MyProperty;
      }
      sw.Stop();
      long millis = sw.ElapsedMilliseconds;

      MessageBox.Show(total.ToString(), millis.ToString());
    }

    public void Test2()
    {
      GC.Collect();
      Stopwatch sw = Stopwatch.StartNew();
      int total = 0;
      for (int i = 0; i < 1000000; i++)
      {
        total += this.MyVirtualProperty;
      }
      sw.Stop();
      long millis = sw.ElapsedMilliseconds;

      MessageBox.Show(total.ToString(), millis.ToString());
    }
  }
}

⌨️ 快捷键说明

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