whatday2.cs

来自「csharp-solution,C#高效编程源码」· CS 代码 · 共 50 行

CS
50
字号

using System;

enum MonthName 
{
    January,
    February,
    March,
    April,
    May,
    June,
    July,
    August,
    September,
    October,
    November,
    December
}

class WhatDay 
{
	static void Main() 
	{
		Console.Write("Please input a day number between 1 and 365: ");
		string line = Console.ReadLine();
		int dayNum = int.Parse(line);

        int monthNum = 0;       
        
        foreach (int daysInMonth in DaysInMonths) {
            if (dayNum <= daysInMonth) {
                break;
            } else {
                dayNum -= daysInMonth;
                monthNum++;
            } 
        }
        
        MonthName temp = (MonthName)monthNum;
        string monthName = temp.Format();
        
        Console.WriteLine("{0} {1}", dayNum, monthName);
    }
    
    // Don't modify anything below here
    static System.Collections.ICollection DaysInMonths 
        = new int[12]{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?