form1.cs

来自「这是.net2005学习不可缺少的教程」· CS 代码 · 共 72 行

CS
72
字号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Generics
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void RegularClick(object sender, EventArgs e)
        {
            // Define the number of values to add and remove
            int iterations = 10000000; // 10,000,000

            // Create an instance of RegularStack and initialise it
            RegularStack s = new RegularStack(iterations);

            // Note the start time
            DateTime start = DateTime.Now;
            // Push the values onto the stack
            for (int f = 0; f < iterations; ++f)
                s.Push(f);

            // Pop the values off the stack
            for (int f = 0; f < iterations; ++f)
                s.Pop();

            // Compute the time taken to complete the test
            float ticks = DateTime.Now.Ticks - start.Ticks;
            float duration = ticks / TimeSpan.TicksPerSecond;

            // Display the duration to the user
            MessageBox.Show("Duration = "
               + String.Format("{0:#0.0000}", duration));
        }

        private void GenericClick(object sender, EventArgs e)
        {
            // Define the number of values to add and remove
            int iterations = 10000000; // 10,000,000

            // Create an instance of GenericStack and initialise it
            GenericStack<int> s = new GenericStack<int>(iterations);

            // Note the start time
            DateTime start = DateTime.Now;
            // Push the values onto the stack
            for (int f = 0; f < iterations; ++f)
                s.Push(f);

            // Pop the values off the stack
            for (int f = 0; f < iterations; ++f)
                s.Pop();

            // Compute the time taken to complete the test
            float ticks = DateTime.Now.Ticks - start.Ticks;
            float duration = ticks / TimeSpan.TicksPerSecond;

            // Display the duration to the user
            MessageBox.Show("Duration = "
               + String.Format("{0:#0.0000}", duration));
        }
    }
}

⌨️ 快捷键说明

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