本文整理汇总了C#中DayOfWeek.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# DayOfWeek.Contains方法的具体用法?C# DayOfWeek.Contains怎么用?C# DayOfWeek.Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DayOfWeek
的用法示例。
在下文中一共展示了DayOfWeek.Contains方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BusinessDays
public static List<int> BusinessDays(DayOfWeek[] WeekEndDays, int Year, int Month)
{
List<int> days = new List<int>();
//Fetch the amount of days in your given month
int daysInMonth = DateTime.DaysInMonth(Year, Month);
//Here we create and enumerable from 1 to daysInMonth
//and ask whether the Datetime object we create belongs to a weekend day,
//if it doen't add it to our IEumerable<int> collection of days.
IEnumerable<int> businessDaysInMonth = Enumerable.Range(1, daysInMonth).Where(d => !WeekEndDays.Contains(new DateTime(Year, Month, d).DayOfWeek));
days.AddRange(businessDaysInMonth);
return days;
}
示例2: RemoveBusinessDays
/// <summary>
/// Remove business days on a DateTime
/// </summary>
/// <param name="date">Date to remove days</param>
/// <param name="days">Days to remove</param>
/// <param name="businessDays">Business days</param>
/// <returns>date</returns>
public static DateTime RemoveBusinessDays(this DateTime date, int days, DayOfWeek[] businessDays)
{
days = Math.Abs(days);
if (businessDays == null || businessDays.Count() == 0)
businessDays = BaseDateTimeExtensions.GetDefaultBusinessDays();
var finalCount = 0;
while (true)
{
if (businessDays.Contains(date.DayOfWeek))
finalCount++;
date = date.AddDays(-1);
if (days == finalCount)
break;
}
return date;
}
示例3: SetSchedule
public void SetSchedule(DayOfWeek[] days, HourOfDay fromHour, MinuteOfHour fromMinute, HourOfDay toHour, MinuteOfHour toMinute)
{
if (!days.Contains (DayOfWeek.Sunday))
{
int num = 0;
while (num < (int)days.Length)
{
if (days[num] < DayOfWeek.Sunday || days[num] > DayOfWeek.Saturday)
{
throw new InvalidEnumArgumentException("days", (int)days[num], typeof(DayOfWeek));
}
else
{
num++;
}
}
for (int i = 0; i < (int)days.Length; i++)
{
this.SetSchedule(days[i], fromHour, fromMinute, toHour, toMinute);
}
return;
}
else
{
throw new ArgumentNullException("days");
}
}
示例4: EndOfBusinessMonth
/// <summary>
/// Get end of business month
/// </summary>
/// <param name="date">base date</param>
/// <param name="businessDays">business days list</param>
/// <returns>End of business month from date</returns>
public static DateTime EndOfBusinessMonth(this DateTime date, DayOfWeek[] businessDays)
{
date = date.EndOfMonth();
if (businessDays == null || businessDays.Count() == 0)
businessDays = BaseDateTimeExtensions.GetDefaultBusinessDays();
while (true)
{
if (businessDays.Contains(date.DayOfWeek))
return date;
date = date.AddDays(-1);
}
}