none
Operator '%' cannot be applied to operands of type

    Question

  • can anyone tell me why the below code throws this error:

    Operator '%' cannot be applied to operands of type 'System.DayOfWeek' and 'System.DayOfWeek'

    thanks, Philly

     

    code:

    int cD = (int)(((rRule.XthDays[0].Day - 1) + 7) % (DayOfWeek.Saturday | DayOfWeek.Monday)); 
    Friday, February 06, 2009 2:16 PM

Answers

  • Because they are enums. You can cast it to int:

    int cD = (int)(((rRule.XthDays[0].Day - 1) + 7) % (int)(DayOfWeek.Saturday | DayOfWeek.Monday));
    • Proposed as answer by Matthew Watson Friday, February 06, 2009 2:20 PM
    • Marked as answer by StaticPhilly Friday, February 06, 2009 2:27 PM
    Friday, February 06, 2009 2:20 PM

All replies

  • Because they are enums. You can cast it to int:

    int cD = (int)(((rRule.XthDays[0].Day - 1) + 7) % (int)(DayOfWeek.Saturday | DayOfWeek.Monday));
    • Proposed as answer by Matthew Watson Friday, February 06, 2009 2:20 PM
    • Marked as answer by StaticPhilly Friday, February 06, 2009 2:27 PM
    Friday, February 06, 2009 2:20 PM
  •  ah right, i was trying to cast them after, DOH! so this is what i have now (works)

    int cD = (((int)(rRule.XthDays[0].Day - 1) + 7) % (int)(DayOfWeek.Saturday | DayOfWeek.Monday));  

    thanks for your help Matthew
    Friday, February 06, 2009 2:26 PM