Shortly speaking. I have 2 lists that contain the same type (but are used for different things), and I want to know if the EITHER list contains an element with a specific name.
My original code, which worked prefectly, was:
if (listA.Any(var => var.Name == strMatch) || listB.Any(var => var.Name == strMatch)) {
This code worked fine, regardless of whether this item was present on one or both lists. Later, I had several “impossible” crashes - things that could never happen. I traced it to this if statement, which never returns true.
It pushed me for centuries ... I could not understand what was going wrong. In the end, I gave up and stuck the brackets around the body of the tube expressions, for example ...
if (listA.Any(var => (var.Name == strMatch)) || listB.Any(var => (var.Name == strMatch))) {
After restarting my program, all the “impossible” errors went away and it functioned normally. Removing unnecessary supports leads to errors.
I have never had this problem with lambda expressions before (especially where they work, and THEN, after several runs work correctly break), and my other lambda expressions work correctly.
Example: The following code works 100% as expected (suppose there is a match in one of the lists)
Item item = ListA.FirstOrDefault(var => var.Name == strMatch) ?? ListB.FirstOrDefault(var => var.Name == strMatch);
What's happening? Why is the compiler picky for some lamda expressions and not others? (Even if they are identical?)
UPDATE :: System Information This was related to Microsoft Visual Studio 2008 (Professional), 32-bit Windows Vista.
UPDATE Link to the video , it was a test on other computers and playable NOT . It seems to me that my computer is doomed. Reinstalling VS is not affected.
Please ignore any sounds of a cat's background, it only meows a lot when it hears me recording something.