Partager via


SYSK 387: Resolving Data Type Conversion Error

Consider the following line of code:

AttendeeAvailability attendeeAvailability;
 . . .
if (attendeeAvailability.WorkingHours.DaysOfTheWeek.Contains(DateTime.Today.DayOfWeek) == false)
{
   . . .
}

You’ll get a compile time error -- Argument 1: cannot convert from 'System.DayOfWeek' to 'Microsoft.Exchange.WebServices.Data.DayOfTheWeek'

 

One way to resolve it is by converting it to a string representation and parsing into the Exchange library known data type, e.g.:

if (attendeeAvailability.WorkingHours.DaysOfTheWeek.Contains((DayOfTheWeek)Enum.Parse(typeof(DayOfTheWeek), DateTime.Today.DayOfWeek.ToString())) == false)
{
   . . .
}