Created
September 19, 2021 21:31
-
-
Save jltrem/c905bbdf412f1461f2255dd48984b6b1 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace ConsoleApp | |
{ | |
public static class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var items = new List<string> { "kirk", "spock", "bones", "scotty" }; | |
foreach ((int index, string item) in items.Indexed()) | |
{ | |
Console.WriteLine($"item[{index}] is {item}"); | |
} | |
} | |
} | |
public static class Sequence | |
{ | |
public static IEnumerable<(int, T)> Indexed<T>(this IEnumerable<T> sequence) => | |
sequence.Select((value, index) => (index, value)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment