Logo

Programming-Idioms

History of Idiom 7 > diff from v116 to v117

Edit summary for version 117 by DavidArno:
[C#] Made the code more up to date idiomatic by using $"" notation

Version 116

2021-09-27, 09:39:27

Version 117

2021-09-27, 09:42:29

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

Variables
i,x,items
Variables
i,x,items
Extra Keywords
indices traverse traversal
Extra Keywords
indices traverse traversal
Imports
using System;
Imports
using System;
Code
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($"{i} {items[i]}");
}
Comments bubble
Using a for loop, we can access the items via the index property