wpf 找不到对 System.Diagnostics.Stopwatch 的引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18534669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't find reference to System.Diagnostics.Stopwatch
提问by jth41
I am attempting to build a simple stopwatch WPF application.
我正在尝试构建一个简单的秒表 WPF 应用程序。
Here is my code:
这是我的代码:
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);
}
}
}
and here
和这里


I am using System.Diagnostics but for some reason I cannot access the Stopwatch
我正在使用 System.Diagnostics 但由于某种原因我无法访问秒表
and also I can't find System.Diagnostics in this Dialogue:
而且我在这个对话中找不到 System.Diagnostics:


Why can't I use System.Diagnostics.Stopwatch and why does System.Diagnostics not appear in the references dialog?
为什么我不能使用 System.Diagnostics.Stopwatch 以及为什么 System.Diagnostics 没有出现在参考对话框中?
回答by Darren
You'll need:
你需要:
Stopwatch stopWatch = new Stopwatch();
You just have (public stopWatch = new StopWatch) which is not how C#objects are created.
您只有 ( public stopWatch = new StopWatch) 这不是C#创建对象的方式。
stopWatchis the instance, StopWatchis the class definition.
stopWatch是实例,StopWatch是类定义。
回答by Jeff
I had a similar problem and turns out I'd typed "StopWatch" instead of "Stopwatch". I hate case sensitivity!
我遇到了类似的问题,结果我输入了“秒表”而不是“秒表”。我讨厌区分大小写!

