c# - 秒表的 Elapsed Ticks 属性差异

标签 c# .net stopwatch elapsedtime

ElapsedTicks & Elapsed.Ticks 是 Stopwatch 的属性,我觉得应该是一样的。 如果它们相同,为什么它们应该给出不同的输出?

代码:

Stopwatch spwt = Stopwatch.StartNew();
spwt.Stop();
Console.WriteLine(spwt.ElapsedTicks);
Console.WriteLine(spwt.Elapsed.Ticks);

输出:

6
16

为什么会出现这种差异?不应该一样吗?

最佳答案

参见 https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.stopwatch.elapsedticks#remarks :

Note

Stopwatch ticks are different from DateTime.Ticks. Each tick in the DateTime.Ticks value represents one 100-nanosecond interval. Each tick in the ElapsedTicks value represents the time interval equal to 1 second divided by the Frequency.

关于c# - 秒表的 Elapsed Ticks 属性差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7432735/

相关文章:

c# - 将时间跨度格式化为 TotalMilliseconds

c# - 如何在 IIS 上部署 WCF 服务应用程序

c# - asp.net 中的替代图像显示

c# - 在 MahApps.Metro 中使用数据绑定(bind) ItemsControl 时显示 WindowCommands 的分隔符

c# - 如何向 RESTful WCF 服务传递和使用 JSON 参数?

c# - Microsoft Graph API 如何创建不记名 msal token

.net - 如何验证程序集是否由我的组织签署?

Android 秒表显示错误的分钟值

C# 试图用秒表包装一个函数