因为我是 C# 的新手,即使我以前用 C 编写过代码,我仍然有一个问题,关于如何在程序已经运行后执行我要求用户输入一组输入的部分。
以下程序打印具有指定月数的日历,但我需要帮助编写另一行代码,在用户已经输入值一次后,要求用户输入要打印的月、年和月数. 我是否必须在我的主函数中进行某种类型的循环,或者我是否必须在我的主函数上方的方法中进行?
static void GenMonth(int month, int year)
{
int daycode, ndim;
PrintHeader(month, year);
ndim=GetNDIM(month,year);
int day=1;
daycode = GetDayCode(month, day, year);
int a,i;
for(a=1;a<=daycode;a++)
{
Console.Write(" ");
}
for (i = 1; i <= GetNDIM(month, year); i++)
{
Console.Write("{0,4}", i);
if (((i + daycode) % 7) == 0)
Console.Write("\n");
}
daycode = GetDayCode(month, day, year);
if (daycode == 6)
{
Console.Write("\n");
}
}
static void Main(string[] args)
{
Console.WriteLine("please enter m,y,n: \n");
string input = Console.ReadLine();
string[] split = input.Split(' ');
int month = Int32.Parse(split[0]);
int year = Int32.Parse(split[1]);
int numberOfMonths = Int32.Parse(split[2]);
int i=0;
for (i = 0; i < numberOfMonths; i++)
{
GenMonth(month, year);
month++;
Console.Write("\n \n");
}
if (month > 12)
{
month = 1;
year++;
}
Console.ReadKey();
}