Pure way to check for null in lambda expressions

I saw a lot of questions about this, but could not find a clean solution:

I have the following lambda expression:

var result = Store.FirstOrDefault(x.Products.Coupon[0] == 100); 

I want to check null for a collection of coupons to check if it is not null, and then compare the first coupon with a value of 100. What would be a clean way to check NULL for a coupon in lambda? I do not want to use the extension method to check for a null value. I would like to do an inline check.

+6
source share
1 answer
 var result = Store.FirstOrDefault(x => x.Products.Coupon != null && x.Products.Coupon.Any() && x.Products.Coupon[0] == 100); 
+14
source

All Articles