Skip to content

Instantly share code, notes, and snippets.

@gowon
Last active July 29, 2016 20:36
Show Gist options
  • Save gowon/c1ce304c9c3edf54756cee9d49f1931e to your computer and use it in GitHub Desktop.
Save gowon/c1ce304c9c3edf54756cee9d49f1931e to your computer and use it in GitHub Desktop.
Getting an index on an enumeration.
// http://stackoverflow.com/a/77542
System.Collections.IEnumerable collection = Enumerable.Range(100, 10);
foreach (var o in collection.OfType<object>().Select((x, i) => new {x, i}))
{
Console.WriteLine("{0} {1}", o.i, o.x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment