C# 8.0 introduced the structs System.Index and System.Range
What is the most concise way to loop through a System.Range?
var owners = new string[] {"Alice", "Bob", "Charlie"};
var pets = new string[] {"Dog", "Cat", "Bird"};
foreach (var index in 1..3) {
var pet = pets[index];
var owner = owners[index];
Console.WriteLine($"{owner} owns a {pet}");
}
The above line foreach (var index in 1..3) { is a compile error.
Type 'System.Range' cannot be used in 'foreach' statement because it neither implements 'IEnumerable' or 'IEnumerable', nor has suitable 'GetEnumerator' method which return type has 'Current' property and 'MoveNext' method