System.DayOfWeek
EnumRepresents the day of the week.
The DayOfWeek
enumeration provides a convenient way to represent the days of the week. Its members are constants that represent each day, starting with Sunday as the first day (value 0) and ending with Saturday (value 6).
This enumeration is commonly used with the DateTime
struct to determine or set the day of the week for a particular date.
using System;
public class Example
{
public static void Main()
{
DateTime today = DateTime.Today;
Console.WriteLine($"Today is {today.DayOfWeek}.");
if (today.DayOfWeek == DayOfWeek.Saturday || today.DayOfWeek == DayOfWeek.Sunday)
{
Console.WriteLine("It's the weekend!");
}
else
{
Console.WriteLine("It's a weekday.");
}
}
}