fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. static class Program
  5. {
  6. static void Main(string[] args)
  7. {
  8. var array = new[] { "hoge", "huga", "tako" };
  9. array.ForEach((s, i) => Console.WriteLine(i + ":" + s));
  10. }
  11. }
  12.  
  13. static class Extensions
  14. {
  15. public static void ForEach<T>(this IEnumerable<T> source, Action<T, int> action)
  16. {
  17. int i = 0;
  18. foreach (var item in source)
  19. {
  20. action(item, i++);
  21. }
  22. }
  23. }
  24.  
  25.  
Success #stdin #stdout 0.02s 37072KB
stdin
Standard input is empty
stdout
0:hoge
1:huga
2:tako