namespace 类的应用_时间
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Time t = new Time();
t.TimeNow();
MessageBox.Show("现在的时间是");
textBox1.Text = t.TimeNow(); //到这里提示错误
}
}
class Time //定义一个时间的类 Time
{
public DateTime TimeNow() //定义一个当前时间TimeNow的方法
{
return DateTime.Now;
}
}
}
已经OK了,谢谢,但还想问一下:如果我把:MessageBox.Show("现在的时间是");这一句改成:
MessageBox.Show("现在的时间是:" & t.TimeNow().ToString() );提示错误,请问如何才能在提示框中显示当前的时间。
把&改成+
本回答被提问者和网友采纳