jth*_*h41 4 .net c# wpf stopwatch visual-studio-2012
我正在尝试构建一个简单的秒表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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
和这里

我正在使用System.Diagnostics但由于某种原因我无法访问秒表
而且我在这个对话中找不到System.Diagnostics:

为什么我不能使用System.Diagnostics.Stopwatch?为什么System.Diagnostics没有出现在引用对话框中?
你需要:
Stopwatch stopWatch = new Stopwatch();
Run Code Online (Sandbox Code Playgroud)
你只有(public stopWatch = new StopWatch)不是如何C#创建对象.
stopWatch是实例,StopWatch是类定义.