ReadLine Example

班~ 副檔名 .cs 不能上傳. 可新增嗎?

ReadLineExample.zip

// Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/// <summary>
/// 示範物件 ReadLine.Example
/// </summary>
namespace ReadLine.Example
{
    public class Program
    {
        /// <summary>
        /// 程式進入啟始點
        /// </summary>
        public static void Main()
        {
            Console.WriteLine(DateTime.Now.ToString());
            // new  建立一個新的物件執行個體。
            ReadLineDEMO Rd = new ReadLineDEMO();
            Console.ReadLine();
        }
    }
}

// ReadLineDEMO.cs

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

namespace ReadLine.Example
{
    class ReadLineDEMO
    {
         public ReadLineDEMO()
        {
            Console.WriteLine("============  ReadLineDEMO Example ============");
            string data = (DateTime.Now.ToLongDateString());
            Console.WriteLine(data);

            string yeardata = "yyyy";
            string Monthdata = "mm";
            string daydata = "dd";
           
            while ((yeardata != data.Substring(0, 4)) ||  (Monthdata != data.Substring(5, 2)) ||  (daydata != data.Substring(8, 2))) // 先執行判斷 , 當條件不等於時,迴圈繼續
            {
            Console.Write(" 請輸入年 : ");
            yeardata = Console.ReadLine();
            Console.Write(" 請輸入月 : ");
            Monthdata = Console.ReadLine();
            Console.Write(" 請輸入日 : ");
            daydata = Console.ReadLine();

            Console.WriteLine(" =============== 輸入結果 ================ ");
             if (yeardata == data.Substring(0, 4))                      // 當輸入年份 成立時
                Console.WriteLine(" 年 = " + (yeardata));             // 成立時顯示 年 =  yeardata
             else
                Console.WriteLine(" 年份輸入錯誤 ");                 // 不成立時顯示年份輸入錯誤

             if (Monthdata == data.Substring(5, 2))                   // 當輸入月份 成立時
                Console.WriteLine(" 月 = " + (Monthdata));          // 成立時顯示 月 = Monthdata
             else
                Console.WriteLine(" 月份輸入錯誤 ");                 // 不成立時顯示月份輸入錯誤

             if (daydata == data.Substring(8, 2))                       // 當輸入月份 成立時
                 Console.WriteLine(" 日 = " + (daydata));             // 成立時顯示 日 = daydata
             else
                 Console.WriteLine(" 日份輸入錯誤 ");                 // 不成立時顯示日輸入錯誤
             if
                 ((yeardata == data.Substring(0, 4)) && (Monthdata == data.Substring(5, 2)) && (daydata == data.Substring(8, 2)))
                 Console.WriteLine(" ===============  輸入正確 ================ ");
             else
                 Console.WriteLine(" ===============  輸入錯誤 ================ ");
            }
        }         
     }
}