dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Extension Method to Update All Items in a List

See how to use an extension method in C# to update all items in a list.


advertisement

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


See how to use an extension method in C# to update all items in a list.

public static IEnumerable<T> ForEach<T>(this IEnumerable<T> collection, Action<T> action)
{
//Loop thru the collection

foreach (T item in collection)
{
action(item);
}
return collection;
}

Example:

californiaClients.ForEach<Client>(timezone => timeZone.value = "PST");

 

Visit the DevX Tip Bank

 





   
Srinath M. S. says: "I would love to leave a footprint in this flat world."
Thanks for your registration, follow us on our social networks to keep up-to-date