Skip to content

Instantly share code, notes, and snippets.

@zenwalk
Forked from uchida/enumerate.cs
Created March 21, 2014 17:18
Show Gist options
  • Save zenwalk/9691149 to your computer and use it in GitHub Desktop.
Save zenwalk/9691149 to your computer and use it in GitHub Desktop.
// GWLlosa's answer in http://stackoverflow.com/questions/521687/c-sharp-foreach-with-index
using System;
using System.Collections.Generic;
using System.Linq;
namespace EnumerateTest {
class Program {
static void Main(string[] args) {
List<int> list = new List<int> {4, 2, 3, 1, 8};
foreach (var iter in list.Select((Value, Index) => new {Value, Index})) {
Console.WriteLine("{0}: {1}", iter.Index, iter.Value);
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment