Monday, May 15, 2017

.ForEach in a lambda shape

This has this example:

Lists.ForEach(x => {
   if (!x.IsAnimal) {
      
// do something
   }
});

 
 

It has been suggested to me today that instead of making a "throw away list" here, that I could instead select with the first half of the .Where clause to a collection (perhaps a list of Tuple<Om,Om> or a dictionary with an Om type for both the key and the value) and then, on a second line of code, do a .ForEach to make the doctorups I need to happen. I do not know how easy (possible) that would be to craft. Maybe we could keep the throwAwayList line of code and just get rid of the left hand side of it, the assignment to throwAwayList.

 
 

Addendum 1/24/2018: You don't need the outer curly braces after the fat arrow (not the C# term) if you only have one line of code.

No comments:

Post a Comment