Snippets Collections
public static class PHVExtensions
{
    public static IEnumerable<T> SetValue<T>(this IEnumerable<T> items, Action<T>
         updateMethod)
    {
        foreach (T item in items)
        {
            updateMethod(item);
        }
        return items;
    }
}

/*
With that method in place, I can write my statement like this:
customers.Where(c => c.IsValid).SetValue(c => c.CreditLimit = 1000).ToList();

Or like this:
var newCustomers = customers.Where(c => c.IsValid).SetValue(c => c.CreditLimit = 1000);

Or like this for Entity Framework:
db.Customers.Where(c => c.IsValid).ToList().SetValue(c => c.CreditLimit = 1000);
*/
star

Mon Jul 04 2022 19:42:53 GMT+0000 (UTC) https://visualstudiomagazine.com/articles/2019/07/01/updating-linq.aspx

#c# #linq #lambda #extensionmethod

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension