我该如何使用这门课程? [英] How can I use this class?

查看:85
本文介绍了我该如何使用这门课程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我怎么能使用System.Environment,我需要这个类来计算算法在我的项目中花费的时间,如果有人知道,请,需要你的帮助,谢谢,请原谅我的语言。 ..

Hello everyone, how can I use the System.Environment, I need this class to calculate the time spent by an algorithm in my project, if anyone know it, please, need your help, thanks and excuse me for my language...

推荐答案

引用:

我需要这个类来计算花费的时间通过我项目中的算法

I need this class to calculate the time spent by an algorithm in my project

当然可以?我会使用 StopWatch类 [ ^ ]用于此目的。

Sure? I would use the StopWatch class[^] for such purpose.


如果您只想计算进程所用的时间,那么当您使用秒表时,为什么要使用Environment? .NET Framework中的/ code>?



http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch(v = vs.110)的.aspx [ ^ ]



您可以使用上面的类来衡量使用.NET Framework所用的时间。



If you just want to calculate the time elapsed by a process, then why are you using Environment when you're having a Stopwatch in the .NET Framework?

http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch(v=vs.110).aspx[^]

You can use the above class, to measure the time elapsed using .NET Framework.

using System;
using System.Diagnostics;
using System.Threading;
class Program
{
    static void Main(string[] args)
    {
        Stopwatch stopWatch = new Stopwatch();
        stopWatch.Start();
        Thread.Sleep(10000);
        stopWatch.Stop();
        // Get the elapsed time as a TimeSpan value.
        TimeSpan ts = stopWatch.Elapsed;

        // Format and display the TimeSpan value. 
        string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
            ts.Hours, ts.Minutes, ts.Seconds,
            ts.Milliseconds / 10);
        Console.WriteLine("RunTime " + elapsedTime);
    }
}





以上代码是从提供的链接中捕获的。



使用上面的代码,您可以轻松设置时间并确定程序中该算法所用的时间。



Above code was captured from the link provided.

Using the above code, you can easily set the time and determine the time that had elapsed for that algorithm in your program.


这篇关于我该如何使用这门课程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆