Search code examples
c#stringdatetimemessagebox

Displaying current datetime in MessageBox in C#


I know this is very trivial but I can't seem to find the answer as I have never done C#. Searched on Google but in vain.

I am trying to display current datetime in MessageBox in C# but I get following error

Cannot convert datetime into string.

Here is the code:

DateTime current = DateTime.Now;
MessageBox.Show(current.ToString);

Solution

  • ToString is a method. You need to do this:

    MessageBox.Show(current.ToString());