开发者

C# Finding Next Active Day of Week

I've got a C# class I'm working with representing a profile that includes some scheduling information indicating how many updates during the day, and which days to update with boolean values for each day of the week. I've seen some posts here and on other sites to find the next instance of a given weekday, etc. but not something where which days one is looking for can vary.

For example, I might be given an object with Monday, Wednesday, and Thursday as true. What's the best way to find the next instance of the next true day of the week?

I can think of some long and drawn out ways to find the next "true" day of the week, but is there something cleaner built in that I'm unfamiliar with that would do the trick? I'd 开发者_JS百科prefer not to use any third party libraries, as that requires lots of special approval from information assurance folks.


Given that it's hardly going to take a long time to loop, that's going to be the simplest approach:

DateTime nextDay = currentDay.AddDays(1);
while (!profile.IsActive(nextDay.DayOfWeek))
{
    nextDay = nextDay.AddDays(1);
}

(That's assuming you've already validated that the profile is active on at least one day... otherwise it'll loop forever.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜