Date time C# get a 10 day cycle working have the exceptions (weekends and holidays) [closed]

StackOverflow https://stackoverflow.com/questions/23329945

  •  10-07-2023
  •  | 
  •  

Question

im 13 and i'm creating a program visual c# that would tell the user what class they have in the specific day of the cycle and period for example on day 1 period 1 you would have math ect could someone help me with the code that would do this "add 1 to an integer everyday except for saturday,sunday and holidays.every 10 days start from 0" i'm sure its simple but i'm a beginner who started a year ago. any help would be greatly appreciated if i didn't explain what i want clearly please say so and i clarify it

Thank You,

Manitha

Was it helpful?

Solution

I believe the following resources will help you:

The while or for loop constructs (to loop over your days and periods): http://msdn.microsoft.com/en-us/library/2aeyhxcd.aspx and http://msdn.microsoft.com/en-us/library/ch45axte.aspx

The continue keyword (to skip days you don't want to process): http://msdn.microsoft.com/en-us/library/923ahwt1.aspx

The DateTime documentation on MSDN: http://msdn.microsoft.com/en-us/library/system.datetime.aspx

Specifically, the DayOfWeek property (to find out what day you are currently looking at in order to skip over it): http://msdn.microsoft.com/en-us/library/system.datetime.dayofweek.aspx

And the AddDays method (to get to the next day): http://msdn.microsoft.com/en-us/library/system.datetime.adddays.aspx

I don't believe what you actually want (maybe it is what you want but working with the correct data type for a problem is often half the battle of finding a solution, and if there's anything I've learned it is that there is almost always a better solution) is to just add one to an integer, which is why I have included the documentation for the DateTime structure.

If you really need an integer representation, consider the text in the remarks section of the DayOfWeek documentation page, specifically the following:

If cast to an integer, its value ranges from zero (which indicates DayOfWeek.Sunday) to six (which indicates DayOfWeek.Saturday).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top