dcsimg
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

WEBINAR:

On-Demand

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


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
 
Thanks for your registration, follow us on our social networks to keep up-to-date