码迷,mamicode.com
首页 > 其他好文 > 详细

类的非常简单的应用

时间:2015-03-29 23:39:34      阅读:184      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!