You could change the check of the week so the function would read:
private bool NthDayOfMonth(DateTime date, DayOfWeek dow, int n){
int d = date.Day;
return date.DayOfWeek == dow && (d-1)/7 == (n-1);
}
Other than that, it looks pretty good and efficient.
More Related Contents:
- Get the correct week number of a given date
- Difference in months between two dates
- Datetime – Get next tuesday
- Compute the DateTime of an upcoming weekday
- Getting day suffix when using DateTime.ToString()
- Convert DateTime to Julian Date in C# (ToOADate Safe?)
- Difference between System.DateTime.Now and System.DateTime.Today
- How can I determine the week number of a certain date?
- Parsing a Auto-Generated .NET Date Object with Javascript/JQuery
- .NET: Get all Outlook calendar items
- Convert Date from Persian to Gregorian
- Should I use public properties and private fields or public fields for data?
- calculating the difference in months between two dates
- Why there are 5 Versions of Timer Classes in .NET?
- “On Exit” for a Console Application [duplicate]
- Does C# have an equivalent to JavaScript’s encodeURIComponent()?
- Troubleshooting BadImageFormatException
- GetFiles with multiple extensions [duplicate]
- Interaction between WebBrowser Control and Windows Forms
- Do I need to lock or mark as volatile when accessing a simple boolean flag in C#?
- SQLite .NET performance, how to speed up things?
- Run a background task from a controller action in ASP.NET Core
- Why do we need the “event” keyword while defining events?
- How to move the cursor or simulate clicks for other applications?
- Could not load file or assembly ‘Microsoft.ReportViewer.Common, Version=11.0.0.0
- Deserialize json in a “TryParse” way
- Using CancellationToken for timeout in Task.Run does not work [duplicate]
- Which exceptions shouldn’t I catch?
- How to prevent a .NET application from loading/referencing an assembly from the GAC?
- Writing a Header using CsvHelper? C#