/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:设计一个控制台程序,实验DateTime类和TimeSpan类,并实验string类各种方法。
* 作 者: 雷恒鑫
* 完成日期: 2012 年 10 月 21 日
* 版 本 号: V1.0
* 对任务及求解方法的描述部分
* 输入描述:设计一个控制台程序,实验DateTime类和TimeSpan类并实验string类各种方法。
* 问题描述:
* 程序输出:
* 程序头部的注释结束
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
enum Color { Red, Yellow, Green }
namespace five_week
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("下面是DateTime类和TimeSpan类的测试");
//使用DateTime类创建一个DateTime的对象dt,并赋值成-8-8的格式
DateTime dt = new DateTime(2008, 8, 8);
//将对象dt以短日期的格式显示出来
Console.WriteLine(dt.ToShortDateString());
//输出对象dt月份值
Console.WriteLine("月份:{0}",dt.Month.ToString());
//使用TimeSpan类创建一个TimeSpan对象ts,并赋值
TimeSpan ts = dt - DateTime.Now;//DateTime.Now表示当前日期
Console.WriteLine("距离北京奥运会还有{0}天",ts.Days.ToString());
Console.WriteLine("下面是String类测试");
double x = 3456.78;
string s0 = string.Format("{0,10:F3}", x);
string s1 = string.Format("{0:######.000}", x);
Console.WriteLine(s0);
Console.WriteLine(s1);
Console.WriteLine();
string str = "this is an apple";
string[] s = str.Split(' ');
for (int i = 0; i < s.Length; i++) //for循环只是为了输出数组s
{
Console.WriteLine(s[i]);
}
Console.ReadKey();
}
}
}
运行结果: