So here is standard code for IValueConverter
{
if (value == null)
return null;
if (value.Equals(true))
return Colors.Red;
return null;
}
And another way:
{
if (true.Equals(value))
return Colors.Red;
return null;
}
So, by using true.Equals() we are saving a null check. What are general approach and best practices in regards to using true.Equals() or “Hello”.Equals() type checks?
P. S. My question is: what is your/general opinion on this: bad/hacky or ok/nice?
The .Equals method generally checks for null anyway, but if you’re trying to optimize your code by removing a single null check, you’re really missing the mark. This is not going to make a difference in virtually any application.