If you mean that you want to iterate a sequence ( IEnumerable ) and call the code for it, you can implement an extension method with an action that is called for each element in the sequence, for example:
public static void ForEach<T>(this System.Collection.Generic.IEnumerable<T> list, System.Action<T> action) { foreach (T item in list) action(item); }
This makes sense if you want to call a little logic (one line) without implementing the foreach () block:
public class MyClass { public void DoSomethingInOneLine() {
user432219
source share