コガネブログ

平日更新を目標に Unity や C#、Visual Studio などのゲーム開発アレコレを書いていきます

【C#】DateTime が特定の曜日の場合に true を返す拡張メソッド

ソースコード

public static class DateTimeExt
{
    public static bool IsMonday( this DateTime self )
    {
        return date.DayOfWeek == DayOfWeek.Monday;
    }
    
    public static bool IsTuesday( this DateTime self )
    {
        return date.DayOfWeek == DayOfWeek.Tuesday;
    }
    
    public static bool IsWednesday( this DateTime self )
    {
        return date.DayOfWeek == DayOfWeek.Wednesday;
    }
    
    public static bool IsThursday( this DateTime self )
    {
        return date.DayOfWeek == DayOfWeek.Thursday;
    }
    
    public static bool IsFriday( this DateTime self )
    {
        return date.DayOfWeek == DayOfWeek.Friday;
    }
    
    public static bool IsSaturday( this DateTime self )
    {
        return date.DayOfWeek == DayOfWeek.Saturday;
    }
    
    public static bool IsSunday( this DateTime self )
    {
        return date.DayOfWeek == DayOfWeek.Sunday;
    }
}