c# - 将秒表转换为整数

标签 c# int stopwatch

我遇到了一点麻烦,我应该将秒表转换为 Int,

Stopwatch czasAlg = new Stopwatch();<p></p>

<p>czasAlg.Start();
//Do something
czasAlg.Stop();</p>

<p>Int32 mojCzas = Convert.ToInt32(czasAlg); //I try to convert but it does't work.</p>

// Int32 mojCzas = Convert.ToInt32(czasAlg.ToString()); //It does't work too.

有解决问题的想法吗?

最佳答案

转换 StopwatchInt32完全没有意义。要获得耗时,您可以使用 ElapsedMilliseconds属性(property)。所以通常的模式是:

Stopwatch watch = Stopwatch.StartNew();
// Do something you would like to measure
watch.Stop();
long totalMilliseconds = watch.ElapsedMilliseconds;
Console.WriteLine("The operation executed in {0} ms", totalMilliseconds);

关于c# - 将秒表转换为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4177332/

相关文章:

c# - C# 与 C 函数互操作的性能损失

java - 2 个数字的范围之和是多少?

java - Java 中的 Swing 计时器秒表

c# - 绑定(bind) OxyPlot Tracker 并在 TextBlock 中设置获取值

c# - 使用不同的服务器验证 token ?

c# - MVC 禁用 EditFor 自动填充

c# - 为什么我不能将 int 拆箱为小数?

Java程序处理非字母字符

java - Android 秒表代码更有效的方法?

ios - 快速导航 View Controller 时倒计时计时器不起作用?