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

📄 program.cs

📁 这是.net2005学习不可缺少的教程
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;

namespace AdvStrStrB2
{
    class Program
    {
        const int numTicks = 10000000;

        static void Main(string[] args)
        {
            String s1 = "When I was young, I listen to the radio.";
            String s2;
            String s3;
            StringBuilder sb = new StringBuilder(s1);

            s2 = s1.Replace('.', '!');

            int startTime, endTime;
            int count;

            // Insert, Remove : String, Interned
            startTime = Environment.TickCount;
            for (count = 0; count < numTicks; count++)
            {
                s3 = s1.Insert(2, "really ");
                s1 = s3.Remove(2, 7);
            }
            endTime = Environment.TickCount;
            Console.WriteLine("Insert/Remove: Interned String " + (endTime - startTime));

            // INSERT : String, not Interned
            startTime = Environment.TickCount;
            for (count = 0; count < numTicks; count++)
            {
                s3 = s2.Insert(2, "really ");
                s2 = s3.Remove(2, 7);
            }
            endTime = Environment.TickCount;
            Console.WriteLine("Insert/Remove: NOT Interned String " + (endTime - startTime));
            
            // INSERT,Remove : StringBuilder
            startTime = Environment.TickCount;
            for (count = 0; count < numTicks; count++)
            {
                sb.Insert(2, "really ");
                sb.Remove(2, 7);
            }
            endTime = Environment.TickCount;
            Console.WriteLine("Insert/Remove: StringBuilder " + (endTime - startTime));

            // Replace : String, interned
            startTime = Environment.TickCount;
            for (count = 0; count < numTicks; count++)
            {
                s1 = s1.Replace("listen to the radio", "play football");
            }
            endTime = Environment.TickCount;
            Console.WriteLine("Replace: String, interned " + (endTime - startTime));

            // Replace : String, NOT interned
            startTime = Environment.TickCount;
            for (count = 0; count < numTicks; count++)
            {
                s2 = s2.Replace("listen to the radio", "play football");
            }
            endTime = Environment.TickCount;
            Console.WriteLine("Replace: String, NOT Interned " + (endTime - startTime));

            // Replace : StringBuilder
            startTime = Environment.TickCount;
            for (count = 0; count < numTicks; count++)
            {
                sb.Replace("listen to the radio", "play football");
            }
            endTime = Environment.TickCount;
            Console.WriteLine("Replace: StringBuilder " + (endTime - startTime));
        }
    }
}

⌨️ 快捷键说明

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