gpt4 book ai didi

c# - 将秒表转换为整数

转载 作者:太空宇宙 更新时间:2023-11-03 19:32:28 25 4
gpt4 key购买 nike

我遇到了一点麻烦,我应该将秒表转换为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com