A DateTime extension method that query if '@this' is a weekend day. - CSharp System

CSharp examples for System:DateTime Week

Description

A DateTime extension method that query if '@this' is a weekend day.

Demo Code

// Licensed under MIT License (MIT) (https://github.com/zzzprojects/Z.ExtensionMethods)
using System;//from   w ww  .ja  v  a2  s .  c  om

public class Main{
        /// <summary>
    ///     A DateTime extension method that query if '@this' is a weekend day.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <returns>true if '@this' is a weekend day, false if not.</returns>
    public static bool IsWeekendDay(this DateTime @this)
    {
        return (@this.DayOfWeek == DayOfWeek.Saturday || @this.DayOfWeek == DayOfWeek.Sunday);
    }
}

Related Tutorials