-1
我有這段代碼,它將是一個秒錶。我的秒錶錯誤(GetTimestamp)
爲什麼不能用實例引用訪問?
錯誤:成員'System.Diagnostics.Stopwatch.GetTimestamp()'無法通過實例引用進行訪問;相反,使用類型名稱來限定它。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
namespace Pocitadlo
{
public partial class Form1 : Form
{
public int minutys = 0, test = 0;
Thread sekund;
TimeSpan ts;
Stopwatch stopky = new Stopwatch();
public Form1()
{
InitializeComponent();
}
public void START_Click(object sender, EventArgs e)
{
sekund = new Thread(Sekund_pocet);
this.START.Visible = false;
this.STOP.Visible = true;
sekund.Start();
}
public void Sekund_pocet()
{
stopky.Start();
stopky.Stop();
ts = stopky.GetTimestamp();
string time = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds/10);
cas.BeginInvoke(new Action(() => cas.Text = Convert.ToString(time)));
}
private void STOP_Click(object sender, EventArgs e)
{
this.STOP.Visible = false;
this.START.Visible = true;
test = 1;
}
}
}
同樣,用英文寫你的代碼,不是每個人都會說捷克語 – Filip 2013-04-21 13:57:19
我同意@Filip大多數語言,不管他們的創建地點在美國英語中,因爲那是1.事實上的全球語言(英語)和2。時髦的美國拼寫已經悄然進入,並且都是一切,所以最好堅持以常規顏色與顏色爲例。 C#是英文的,所以你的代碼也應該是。 – Clint 2013-04-21 14:08:56