I am aware. I probably should have said "inspired".
if (date is { Month: 10, Day: <=7, DayOfWeek: DayOfWeek.Friday }) { ... }
This following would do the same thing before the is operator: static bool IsFirstFridayOfOctober(DateTime date)
{
return date.Month == 10
&& date.Day <= 7
&& date.DayOfWeek == DayOfWeek.Friday;
}
And then: if IsFirstFridayOfOctober(date) {
...
}
I understand it is more verbose. But do we really need a new operator for this? I was getting on fine without it. if (customer != null)
{
customer.Order = GetCurrentOrder();
}
vs if (customer is not null)
{
customer.Order = GetCurrentOrder();
}
Is there really any benefit in adding "is/is not"? I would argue no. So I categorise that as being of "dubious benefit" and there are many similar small features, keywords etc. that get added each release where they might save a few lines of code somewhere but I've never seem them used that often.