新表达式需要在键入后使用 ()、[] 或 {}
本文关键字:表达式 | 更新日期: 2023-09-27 18:35:38
所以我正在尝试制作一个基本的秒表程序,但我不断收到此错误"新表达式在键入后需要 ()、[] 或 {}"这是我的代码:
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
int ms, s, m, h;
Timer timer1 = new Timer
public Form1()
{
InitializeComponent();
ms = 0;
}
private void timer1_Tick(object sender, EventArgs e)
{
ms = ms + 1;
if (ms == 9)
{
ms = 0;
s = s + 1;
lblsecond.Text = s.ToString();
if (s == 59)
{
s = 0;
m = m + 1;
lblmin.Text = m.ToString();
if (m == 59)
{
m = 0;
h = h + 1;
lblhur.Text = h.ToString();
{
lblmsec.Text = ms.ToString();
}
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label1_Click_1(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void button3_Click(object sender, EventArgs e)
{
ms = 0;
h = 0;
s = 0;
m = 0;
timer1.Enabled = false;
lblhur.Text = "00";
lblmin.Text = "00";
lblmsec.Text = "00";
lblsecond.Text = "00";
}
}
}
Timer timer1 = new Timer();
创建新类时,需要调用类的构造函数。 阅读有关 C# 的一些基础知识教程。你错过了基础知识!
此行
Timer timer1 = new Timer();
你能指定哪一行给你错误吗?但也可能是这个,为什么你周围有{}?
lblhur.Text = h.ToString();
{
lblmsec.Text = ms.ToString();
}
或
Timer timer1 = new Timer
自
Timer timer1 = new Timer();
在此行
Timer timer1 = new Timer
计时器的结尾需要 () 和 ; ,如下所示:
Timer timer1 = new Timer();