求解C#编程题 30
定义一个时钟类,以及类的三个属性:时,分,秒,并定义在类上的各种操作(时间的加、减),要求用操作符重载来完成。最后写一个程序来测试所定义的类的操作符重载功能...
定义一个时钟类,以及类的三个属性:时,分,秒,并定义在类上的各种操作(时间的加、减),要求用操作符重载来完成。最后写一个程序来测试所定义的类的操作符重载功能
展开
展开全部
using System;
using System.Timers;
class TestTimer
{
public static void Main()
{
Timer timer = new Timer();
timer.Elapsed += new ElapsedEventHandler( DisplayTimeEvent );
timer.Interval = 1000;
timer.Start();
timer.Enabled = true;
while ( Console.Read() != 'q' )
{
//-------------
}
}
public static void DisplayTimeEvent( object source, ElapsedEventArgs e )
{
Console.Write(\r{0}, DateTime.Now);
}
}
using System.Timers;
class TestTimer
{
public static void Main()
{
Timer timer = new Timer();
timer.Elapsed += new ElapsedEventHandler( DisplayTimeEvent );
timer.Interval = 1000;
timer.Start();
timer.Enabled = true;
while ( Console.Read() != 'q' )
{
//-------------
}
}
public static void DisplayTimeEvent( object source, ElapsedEventArgs e )
{
Console.Write(\r{0}, DateTime.Now);
}
}
展开全部
public class Timer
{
int hour;
public int Hour
{
get { return hour; }
set { hour = value; }
}
int minute;
public int Minute
{
get { return minute; }
set { minute = value; }
}
int second;
public int Second
{
get { return second; }
set { second = value; }
}
public DateTime Calculate(DateTime DateTime,TimeSpan TimeSpan,string s)
{
DateTime d = new DateTime();
if (s == "+") d = DateTime + TimeSpan;
if (s == "-") d = DateTime - TimeSpan;
return d;
}
}
{
int hour;
public int Hour
{
get { return hour; }
set { hour = value; }
}
int minute;
public int Minute
{
get { return minute; }
set { minute = value; }
}
int second;
public int Second
{
get { return second; }
set { second = value; }
}
public DateTime Calculate(DateTime DateTime,TimeSpan TimeSpan,string s)
{
DateTime d = new DateTime();
if (s == "+") d = DateTime + TimeSpan;
if (s == "-") d = DateTime - TimeSpan;
return d;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询