잠토의 잠망경

학교 강의 내용 1st 본문

공부/C sharp

학교 강의 내용 1st

잠수함토끼 2007. 9. 27. 14:51


Charles Petzold의 내용을 실습했습니다.
Date.cs
==================================================================================
using System;

class PropertyTest
{
    static void Main()
    {
        Date dateMoonWalk = new Date();

        try
        {
            dateMoonWalk.Year = 1969;
            dateMoonWalk.Month = 12;
            dateMoonWalk.Day = 20;
      
            Console.WriteLine("Moon walk: {0}, Day of Year: {1}",
                                dateMoonWalk, dateMoonWalk.DayOfYear());
        }
        catch (Exception e)
        {
            if(e.ToString() == "Year")
            {
                Console.WriteLine("Wrong Year");
            }
            else if (e.ToString() == "Month")
            {
                Console.WriteLine("Wrong Month");
            }
            else
            {
                Console.WriteLine("Wrong Day");
            }
        }
    }
}
===================================================================================

PropertyTest.cs

===================================================================================
using System;

class PropertyTest
{
    static void Main()
    {
        Date dateMoonWalk = new Date();

        dateMoonWalk.Year = 1969;
        dateMoonWalk.Month = 7;
        dateMoonWalk.Day = 20;

        Console.WriteLine("Moon walk: {0}, Day of Year: {1}",
                            dateMoonWalk, dateMoonWalk.DayOfYear());

    }
}
===================================================================================
실행화면

사용자 삽입 이미지

Comments