SyntaxFix
Write A Post
Hire A Developer
Questions
Using Linq we can simplify this by this
Enumerable.Range(0, (int)(to - from).TotalHours + 1) .Select(i => from.AddHours(i)).Where(date => date.TimeOfDay >= new TimeSpan(8, 0, 0) && date.TimeOfDay <= new TimeSpan(18, 0, 0))