Code will work if input is of type not containing NULL. There is an implicit conversion of all non-empty types to their nullable copies, so input will simply be canceled to NULL to compare with the property value.
The only difference in behavior, as you already mentioned, is that if input is null , then the second fragment cannot distinguish attribute null when it should be false , and where Description is null , where it should be true .
Oh, and that assumes attribute is a local variable or field. If this property (or actually a more complex expression), then it can have side effects or lead to a different value when calculated twice, as it happens in the first fragment, but not in the second, which is the difference in behavior.
This, of course, assumes a single-threaded context. In a multi-threaded context, if an attribute is accessible from another thread (either because it is available, or because it is closed in a lambda that undergoes another thread), then the value may be different each time it is evaluated, so there are two fragments differ for the same reason as in the previous paragraph.
Servy Dec 05 '16 at 2:52 p.m. 2016-12-05 14:52
source share