2021年2月5日星期五

An object reference is required for the non-static field, method, or property 'DateTime.TimeOfDay'

using System;  using System.Collections.Generic;  using System.ComponentModel;  using System.Data;  using System.Drawing;  using System.Linq;  using System.Text;  using System.Threading.Tasks;  using System.Windows.Forms;  using System.Media;    namespace NotificationDemo  {      public partial class NotificationDemo : Form      {          public NotificationDemo()          {              InitializeComponent();          }            // Variables //              // Messaging System //          public void Alert(string msg)          {              NotifyForm frmn = new NotifyForm();              frmn.showAlert(msg);          }          private void BtnNotify_Click(object sender, EventArgs e)          {              this.Alert("Default Message");                SoundPlayer player = new SoundPlayer();              player.SoundLocation = @"C:\Windows\Media\Alarm03.wav";              player.Play();          }            // Basic Schedule SysFunction             public string currenttime;          public string messagetime;            private void timer1_Tick(object sender, EventArgs e)          {              currenttime = DateTime.TimeOfDay.ToString("hh:mm:ss tt");          }      }  }  

Error is at:

currenttime = DateTime.TimeOfDay.ToString("hh:mm:ss tt");

I don't know whether this has to deal with the method I'm setting the time with, something else. Need assistance determining if 'DateTime.TimeOfDay' is still a valid way of taking time out of the system than something else.

https://stackoverflow.com/questions/66073467/an-object-reference-is-required-for-the-non-static-field-method-or-property-d February 06, 2021 at 12:05PM

没有评论:

发表评论