Check if dateTime is a weekend or a weekday

前端 未结 6 1904
日久生厌
日久生厌 2021-02-03 20:48


        
6条回答
  •  梦谈多话
    2021-02-03 21:16

    You wrote wrong varable in the following if statement:

    if ((dayToday == DayOfWeek.Saturday) || (dayToday == DayOfWeek.Sunday))
    {
        Console.WriteLine("This is a weekend");
    }
    

    instead of dayToday you must use day varable in the condition.

    UPDATE: Also you made mistake in condition. There must be or instead of and.

    Correct code is

    if ((day == DayOfWeek.Saturday) || (day == DayOfWeek.Sunday))
    {
        Console.WriteLine("This is a weekend");
    }
    

提交回复
热议问题