int[] numbers = { 1, 2, 3, 4, 5, 6 }; Range range = 1..4; int[] sliced = numbers[range]; // sliced is { 2, 3, 4 }
string sentence = "The quick brown fox jumps over the lazy dog"; Range range = 4..9; string sliced = sentence[range]; // sliced is "quick"In this example, we create a string and a Range object that represents the slice from index 4 to index 9 (inclusive). We then use the Range object to slice the string and assign the result to a new string. Package library: System.Runtime.CompilerServices.Unsafe.