【发布时间】:2016-11-29 17:04:56
【问题描述】:
我只需要一些关于如何显示该月中的哪些日期属于那天的指导。例如,如果用户输入 0 表示星期一和该月的 31 天,它将显示所有的 momdays 以及星期一对应于该月的哪个日期?谢谢我到目前为止有这个,但它似乎不适用于用户输入。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Calendar
{
class Program
{
static int startDay = new int();
static int totalDays = new int();
static void Main(string[] args)
{
Console.Write("Enter the day the first falls on (Mon = 0, etc): ");
startDay = Convert.ToInt32(Console.ReadLine());
Console.Write("How many days in the month? ");
totalDays = Convert.ToInt32(Console.ReadLine());
}
public static List<DateTime> getDates()
{
List<DateTime> lstSundays = new List<DateTime>();
int intMonth = DateTime.Now.Month;
int intYear = DateTime.Now.Year;
int intDaysThisMonth = DateTime.DaysInMonth(intYear, intMonth);
DateTime oBeginnngOfThisMonth = new DateTime(intYear, intMonth, 1);
for (int i = 1; i < intDaysThisMonth + 1; i++)
{
if (oBeginnngOfThisMonth.AddDays(i).DayOfWeek == DayOfWeek.Sunday)
{
lstSundays.Add(new DateTime(intYear, intMonth, i));
}
}
return lstSundays;
}
}
}
【问题讨论】:
-
欢迎来到 Stack Overflow。请将代码发布为文本而不是图片,您的要求太模糊,我们目前无法为您提供帮助。请阅读codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question 并记住,Stack Overflow 的目标是创建一个高质量问题和答案的存储库。
-
嗯...我不认为创建一个新的个人资料并再次提出相同的问题,与最初向您指出的完全相同的缺乏信息,将会帮助。 stackoverflow.com/questions/40869698/…
-
我正要发布同样的内容。将此添加到您的问题“程序应该询问您该月的第一天所在的星期几(编号在 0 和 6 之间)以及该月有多少天。它还应该询问月份的名称。你希望得到怎样的帮助?人们无法读懂你的想法