I am maintaining a project and have come across some code which I can't understand. LINQ query:
var toDraw = from tile in testArr.AsEnumerable() where tile.Item_Business_Unit != null ? ((tile.Ending_Date >= DateTime.Now || tile.Ending_Date == DateTime.MinValue) && ((tile.Sales_Code == null) || (tile.Sales_Code.ToString() == customerNumber) || (tile.Sales_Code.ToString() == cpg)) && (tile.Unit_Price != 0)) : ((tile.Ending_Date >= DateTime.Now || tile.Ending_Date == DateTime.MinValue) && ((tile.Sales_Code == null) || (tile.Sales_Code.ToString() == customerNumber) || (tile.Sales_Code.ToString() == cpg)) && (tile.Unit_Price != 0)) select tile; From what I understand, from an array a tile is being selected which has the following criteria:
- Ending date can be
datetime.nowordatetime.minvalue - Sales code can be null or can be equal to customer no or cpg
- Unit price should be greater than 0
But I am not understanding why there is a conditional expression after tile.Item_Business_Unit since both of the conditions perform the same thing. So will the item be selected even if it has a null business unit? And does this work different from normal if/else operations?
Any suggestions would be very appreciated.


tile.Item_Business_Unitwas used in the query, but it isn't anymore - the ternary just remained since the guy who made the change didn't bother removing it.Item_Business_Unit- it's possible it has a side-effect you could be removing. It would be rather sneaky (and is the kind of offence you'd kill the other guy for :P), but it's possible. If it has no side-effects, you can remove it safely.