using System; using System.Collections.Generic; using System.Linq; public class Test { public static void Main() { Print(new[] { 1, 2, 3, 4 }); Print(new[] { "hello", "world" }); Print(new[] { "just one!" }); } public static void Print(IEnumerable collection) { if (collection.Any()) { var seenFirst = false; T prev = default(T); foreach (var current in collection) { if (seenFirst) Foo(prev); seenFirst = true; prev = current; } Bar(prev); } } public static void Foo(object o) { Console.WriteLine("Foo: {0}", o); } public static void Bar(object o) { Console.WriteLine("Bar: {0}", o); } }