I have an IEnumerable
not 100% sure I like this but you could always delay the use of item until you've moved one step in to the IEnumerable array, that way when you get to the end you've not used the last entry.
it avoids having to force a count on the enumerator.
object item = null;
foreach (var a in items)
{
// if item is set then we can use it.
if (item != null)
{
// not final item
f(item);
}
item = a;
}
// final item.
g(item);