"Automatic Index and Range Support"

// This class has everything required for automatic Index and Range support
class NumberLine {
	public int StartValue { get; }
	public int Length { get; }

	public NumberLine(int startValue, int length) {
		StartValue = startValue;
		Length = length;
	}

	public int this[int index] {
		get {
			if (index >= Length) throw new ArgumentOutOfRangeException(nameof(index));
			return StartValue + index;
		}
	}

	public IEnumerable<int> Slice(int offset, int length) {
		if (offset + length > Length) throw new ArgumentOutOfRangeException(nameof(length));
		for (var i = 0; i < length; ++i) yield return StartValue + offset + i;
	}
}

// Here we demonstrate the automatic support
var numberLine = new NumberLine(0, 10);

Console.WriteLine(numberLine[Index.Start]); // 0
Console.WriteLine(numberLine[Index.FromEnd(1)]); // 9

Console.WriteLine(String.Join(", ", numberLine[..])); // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Console.WriteLine(String.Join(", ", numberLine[3..7])); // 3, 4, 5, 6
Console.WriteLine(String.Join(", ", numberLine[^7..^3])); // 3, 4, 5, 6


Code snippet taken from "Two Decades of C#: A Reference - C# 8".