Tuesday, 23 December 2014

How to fix error An object reference is required for the non-static field, method, or property 'System.DateTime.ToShortTimeString()'

Watch this example on YouTube

 To fix the error:
An object reference is required for the non-static field, method, or property 'System.DateTime.ToShortTimeString()'  

Replace
   string d = DateTime.ToShortDateString();
   string t = DateTime.ToShortTimeString();
With
  string d = DateTime.Today.ToShortDateString();
  string t = DateTime.Now.ToShortTimeString();

No comments:

Post a Comment