包含带参数的构造函数,包含SetTime方法,可以设置成员变量,包含PrintTime方法,可以按如下格式打印Time(XX:XX:XX)
胡写几句,live41看看对不对^_^ using System; class Time { int Hour,Minute,Second; public Time(System.DateTime SystemTime) { this.Hour = SystemTime.Hour; this.Minute = SystemTime.Minute; this.Second = SystemTime.Second; } public void PrintTime() { Console.WriteLine("现在是 {0}:{1}:{2} ",Hour,Minute,Second); } public void SetTime(int Hour,int Minute,int Second) { this.Hour = Hour; this.Minute = Minute; this.Second = Second; } } class Test { public static void Main() { int Hour,Minute,Second; System.DateTime SystemTime = System.DateTime.Now; Time time = new Time(SystemTime);
time.PrintTime(); Console.WriteLine("重新设置时间:11:11:11"); Hour =11; Minute =11; Second =11; time.SetTime(Hour,Minute,Second); time.PrintTime(); Console.ReadLine(); } }
噢,你是指这样吗? using System; class Time { int Hour,Minute,Second;
public Time(System.DateTime SystemTime) {
this.Hour = SystemTime.Hour; this.Minute = SystemTime.Minute; this.Second = SystemTime.Second; }
public void PrintTime() { Console.WriteLine("现在是 {0}:{1}:{2} ",Hour,Minute,Second); }
public int hour { get { return Hour; } set { Hour = value; } } public int minute { get { return Minute; } set { Minute = value; } }
public int second { get { return Second; } set { Second = value; } }
} class Test { public static void Main() { System.DateTime SystemTime = System.DateTime.Now;
Time time = new Time(SystemTime);
time.PrintTime(); Console.WriteLine("重新设置时间:11:11:11"); time.hour =11; time.minute =11; time.second =11; time.PrintTime(); Console.ReadLine(); } }