dcsimg
 

Submitted by: Srinath M S(srinath_ms@yahoo.com)

Friday Aug 30th 2019 by Srinath M S

Language: .NET, Expertise: Beginner - See how to use an extension method in C# 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");
Home
Mobile Site | Full Site