dcsimg
LinkedIn
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » .NET » C#
Language: .NET
Expertise: Beginner
Aug 30, 2019

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.

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");
Srinath M S
 
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date