在C#中的MessageBox中显示当前日期时间

Ali*_*Ali 3 c# string datetime messagebox

我知道这是非常微不足道的,但我似乎无法找到答案,因为我从未做过C#.在Google上搜索但是徒劳无功.

我试图在C#中的MessageBox中显示当前的日期时间,但我得到以下错误

Cannot convert datetime into string.

这是代码:

DateTime current = DateTime.Now;
MessageBox.Show(current.ToString);
Run Code Online (Sandbox Code Playgroud)

Emi*_*adh 8

ToString是一种方法.你需要这样做:

MessageBox.Show(current.ToString());
Run Code Online (Sandbox Code Playgroud)