using System.Collections.Generic;
public static void Main()
var arr = new[] { "Zero", "One", "Two", "Three", "Four", "Five" };
Console.WriteLine("Example One - Accessing indices in foreach");
foreach (var (str, idx) in arr.Select((idx, str) => (idx, str)))
Console.WriteLine($"idx={idx}, str={str}");
Console.WriteLine("\nExample Two - string join");
Console.WriteLine(",".JoinEx(arr));
Console.WriteLine("\nExample Three - pattern matching");
BaseClass downCastMe = new DerivedClass();
if (downCastMe is DerivedClass downCasted)
Console.WriteLine(downCasted.IsBase());
Console.WriteLine($"Not {nameof(DerivedClass)}");
Console.WriteLine("\nExample Four - enumerable ranges");
foreach (var obj in arr[2..5])
Console.WriteLine("\nDone!");
public static class StrExtensions
public static string JoinEx(this string separator, IEnumerable<string> input) => string.Join(separator, input);
public virtual bool IsBase() => true;
public class DerivedClass : BaseClass
public override bool IsBase() => false;