The Fourth Dimension Space

枯叶北风寒,忽然年以残,念往昔,语默心酸。二十光阴无一物,韶光贱,寐难安; 不畏形影单,道途阻且慢,哪曲折,如渡飞湍。斩浪劈波酬壮志,同把酒,共言欢! -如梦令

C# 猜数字小游戏(IDisposable接口练习)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class iTimer:IDisposable
{
    String mes;
    DateTime s;
    public iTimer(String mes)
    {
        this.mes = mes;
        s = DateTime.Now;
    }

    public void Dispose()
    {

        DateTime t = DateTime.Now;
        TimeSpan ts = t - s;
        Console.Error.WriteLine("spent time(in Milliseconds):");
        Console.Error.WriteLine(ts.TotalMilliseconds);

    }

    public static void Main()
    {

        using (iTimer t = new iTimer("game"))
        {
            int ans = 10;
            int input = Int32.Parse(Console.ReadLine());

            while(ans!=input)
            {
                Console.WriteLine("please try again.");
                input = Int32.Parse(Console.ReadLine());
            }
            Console.WriteLine("Correct!");
                
        }

        Console.Error.WriteLine("the program is terminated");
        

    }


}

posted on 2014-09-21 12:26 abilitytao 阅读(460) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理