类的非常简单的应用

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;
    }
}

输出结果

posted @ 2015-03-29 22:43  一边挖鼻屎一边  阅读(99)  评论(0编辑  收藏  举报