CSharp examples for System.Collections.Generic:IList
Applies the action to every item in the list Deals with null IList
using System.Linq; using System.Collections.Generic; using System.Collections; using System;//w w w.jav a 2 s . c o m using Cirrious.CrossCore.Platform; public class Main{ /// <summary> /// Applies the action to every item in the list /// Deals with null IList /// </summary> /// <typeparam name="T"></typeparam> /// <param name="source">The source.</param> /// <param name="action">The action.</param> public static IList<T> SafeForEach<T>(this IList<T> source, Action<T> action) { if (source != null && source.Count > 0) { foreach (var item in source) { action(item); } } return source; } }