C# 获取运行时间

//==方法定义:==========
using System.Diagnostics;
 
public delegate void Action();
public static class Run {
    public static double GetRunTime(Action method) {
        Stopwatch sw = new Stopwatch();
        sw.Start();
        method();
        sw.Stop();
        return sw.Elapsed.TotalMilliseconds;
    }
}
 
 
//==调用代码:注意用Lamp表达式==========
Run.GetRunTime(
    ()=>{
        DoSomeThing();
    }
).ToString()

 

 
 
posted @ 2012-01-09 17:36  学海一叶  阅读(427)  评论(0编辑  收藏  举报