Sometimes you just need a ternary statement, i.e. you don't want to return a value from the condition ? true : false construct. Here is an extension method to help you out (the usage example isn't the best). class Program { static void Main(string[] args) { List<string> test = new List<string>(); ArrayList source = new ArrayList(); source.Add(1); source.Add("hello"); source.Each<object>(x => (x is String).IfElse ( () => test.Add((string)x), () => test.Add(x.ToString())...
Funny this isn't in the provided Enumerable extension methods. In any case, here it is: internal static void Each<T>(this IEnumerable<T> @this, Action<T> action) { foreach(T t in @this) action(t); } internal static void Each<T>(this IEnumerable @this, Action<T> action) { foreach (object t in @this) if (t is T) { action((T)t); } } An example: objects.Each(x => DoSomethingFunky(x, "some parameter"));...
Put your favorite bookmarklet at your fingertips.