I have two code samples. One works and returns the correct result, one chose the null reference exception. What's the difference? I know that some kind of magic happens with capturing variables to express lambda, but I donβt understand what is going on behind the scenes.
int? x = null; bool isXNull = !x.HasValue; // this works var result = from p in data.Program where (isXNull) select p; return result.Tolist(); // this doesn't var result2 = from p in data.Program where (!x.HasValue) select p; return result2.ToList();
source share