首页 > 其他 > 详细

类的非常简单的应用

时间:2015-03-29 23:38:39      阅读:224      评论:0      收藏:0      [点我收藏+]
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;
    }
}

输出结果

技术分享

类的非常简单的应用

原文:http://www.cnblogs.com/czyhhxx/p/4376641.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!