类的非常简单的应用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; public class Time { private int Year; int Month; int Date; int Hour; int Minute; int Second; public Time(System.DateTime time) { Year = time.Year; Month = time.Month; Date = time.Day; Hour = time.Hour; Minute = time.Minute; Second = time.Second; }//constructor public void DisplayCurrentTime(){ Console.WriteLine(Year + "\0" + Month + "/" + Date + "\0" + Hour + ":" + Minute + ":" + Second); } } class Program { static void Main(string[] args) { System.DateTime currentTime = System.DateTime.Now; Time t = new Time(currentTime); t.DisplayCurrentTime(); Console.ForegroundColor = ConsoleColor.Cyan; } }
输出结果