Logo

Programming-Idioms

History of Idiom 7 > diff from v39 to v40

Edit summary for version 40 by :
[Csharp] items is supposed to be given. We focus on the code of the loop.

Version 39

2016-02-05, 10:51:07

Version 40

2016-02-05, 10:51:50

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Imports
using System;
Imports
using System;
Code
string[] items = { "First", "Last" };
for (int i = 0; i < items.Length; i++)
{
    Console.WriteLine("{0} {1}", i, items[i]);
}
Code
for (int i = 0; i < items.Length; i++)
{
    Console.WriteLine("{0} {1}", i, items[i]);
}