-
-
Save zenwalk/9691149 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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