1

I am totally new to C# and coding. I'm working on a challenge in a course I'm taking which in part needs to satisfy the following business rule:

Business Rule 1: Initialize the calendar controls. Make sure the end of the previous assignment date is set to today. Make sure the start date of the new assignment is set for an additional 14 days from today. Make sure the end date of the new assignment is set for an additional 21 days from today.

When I initially set these dates the selected date was correct, but since it is late in the month, I would have to click to the next month to see the selected date:

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                previousCalendar.SelectedDate = DateTime.Now.Date;
                newCalendar.SelectedDate = DateTime.Now.Date.AddDays(14);
                endCalendar.SelectedDate = DateTime.Now.Date.AddDays(21);
            }

so I added the following 2 lines of code (of course within the curly brackets) to show the selected date:

            newCalendar.VisibleDate = newCalendar.SelectedDate;
            endCalendar.VisibleDate = endCalendar.SelectedDate;

This seems a little cumbersome, is there a way to consolidate these last two lines?

Again, I'm a total noob so I'm sure the answer will be obvious to everyone else here.

Newbie
  • 11
  • 1

1 Answers1

0
newCalendar.VisibleDate = newCalendar.SelectedDate = DateTime.Now.Date.AddDays(14);
endCalendar.VisibleDate = endCalendar.SelectedDate = DateTime.Now.Date.AddDays(21);

If this is what you mean, then yes. You can set the same value to 2 different properties in the same line of code. Sometimes keeping your steps as separate lines is better because it can make your code more readable for someone else who isn't familiar with it, but in this case, I think combining like above is reasonable.

erastl
  • 421
  • 4
  • 9