Consider the two following similar code samples.
One where
clause.
bool validFactory
= fields
.Where(
fields => field.FieldType == typeof( DependencyPropertyFactory<T> ) &&
field.IsStatic )
.Any();
Two where
clauses.
bool validFactory
= fields
.Where( field => field.FieldType == typeof( DependencyPropertyFactory<T> ) )
.Where( field => field.IsStatic )
.Any();
I prefer the second since I find it more readable and it causes less formatting issues, especially when using auto-formatting. It is also clearer when placing comments next to the separate conditions (or even above) to clarify the intent.
My intuition says the second code sample would be less efficient. I could of course write a simple test myself (and will if nobody knows the answer). For now I thought this is perfect food for SO. ;p
- Is one more efficient than the other?
- Is the compiler smart enough to optimize this?