Calculate working days and excluding specific dates (Holidays) I read some questions/answers related to functions in C# to calculate the working days; some use an extended code to achieve that.

I have a data table with more than 50,000 rows and I required an effective method to calculate this information.

I created the following extension in C# that return a number of days (Integer), between two dates; excluding dates (Based on a list of DateTime)

/// &lt;summary&gt; Get working days between two dates (Excluding a list of dates - Holidays) &lt;/summary&gt;
/// &lt;param name="dtmCurrent"&gt;Current date time&lt;/param&gt;
/// &lt;param name="dtmFinishDate"&gt;Finish date time&lt;/param&gt;
/// &lt;param name="lstExcludedDates"&gt;List of dates to exclude (Holidays)&lt;/param&gt;
public static int fwGetWorkingDays(this DateTime dtmCurrent, DateTime dtmFinishDate, List&lt;DateTime&gt; lstExcludedDates)
{
    Func&lt;DateTime, bool&gt; workDay = currentDate =&gt;
    (
        currentDate.DayOfWeek == DayOfWeek.Saturday ||
        currentDate.DayOfWeek == DayOfWeek.Sunday ||
        lstExcludedDates.Exists(evalDate =&gt; evalDate.Date.Equals(currentDate.Date))
    );

    return Enumerable.Range(0, 1 + (dtmFinishDate - dtmCurrent).Days).Count(intDay =&gt; workDay(dtmCurrent.AddDays(intDay)));
}


Does there exists some way to improve this method.
Bug
There is a bug in this method. It counts non-working days because the workDay condition needs to be negated.
return 
    Enumerable
        .Range(0, (finishDate - current).Days)
        .Count(day =&gt; !isExcludedDate(current.AddDays(day)));


Naming
Then comes the naming. What's with the prefixes fw, dtm, lst? In C# we don't use the hungarian notation. You should use either the camelCase or PascalCase naming where appropriate.

Closures
You could take advantage of closures and simplify the Count
public static int GetWorkingDays(this DateTime current, DateTime finishDateExclusive, List&lt;DateTime&gt; excludedDates)
{
    Func&lt;int, bool&gt; isWorkingDay = days =&gt;
    {
        var currentDate = current.AddDays(days);
        var isNonWorkingDay =
            currentDate.DayOfWeek == DayOfWeek.Saturday ||
            currentDate.DayOfWeek == DayOfWeek.Sunday ||
            excludedDates.Exists(excludedDate =&gt; excludedDate.Date.Equals(currentDate.Date));
        return !isNonWorkingDay;
    };
   
    return Enumerable.Range(0, (finishDateExclusive - current).Days).Count(isWorkingDay);
}  

Depending on how long the List&lt;DateTime&gt; excludedDates is, you may consider using a HashSet&lt;DataTime&gt;.
Upper range

1 + (dtmFinishDate - dtmCurrent).Days


Most .NET APIs consider the upper range exclusive thus it might be a good idea to follow this style by removig the +1 and renaming the finishDate to finishDateExclusive.