我正在尝试构建一个简单的秒表 WPF 应用程序。
这是我的代码:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Diagnostics;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public stopWatch = new Stopwatch();
private void startTimer()
{
stopWatch.Start();
Dispatcher.BeginInvoke(DispatcherPriority.Render, new ThreadStart(ShowElapsedTime));
}
void ShowElapsedTime()
{
TimeSpan ts = stopWatch.Elapsed;
lblTime.Text = String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
}
}
}
这里
我正在使用 System.Diagnostics 但由于某些原因我无法访问 Stopwatch
而且我在此对话中找不到 System.Diagnostics:
为什么我不能使用 System.Diagnostics.Stopwatch,为什么 System.Diagnostics 没有出现在引用对话框中?
最佳答案
你需要:
Stopwatch stopWatch = new Stopwatch();
您只有 (public stopWatch = new StopWatch
) 而不是 C#
对象的创建方式。
stopWatch
是实例,StopWatch
是类定义。
关于c# - 找不到对 System.Diagnostics.Stopwatch 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18534669/