int[] array1 = {1, 2, 3, 4, 5}; int[] array2 = {3, 4, 5}; bool isEqual = array1.AsSpan().Slice(2, 3).SequenceEqual(array2); Console.WriteLine(isEqual); //Output: True
char[] array1 = {'a', 'b', 'c', 'd', 'e'}; char[] array2 = {'a', 'c', 'e'}; bool isEqual = array1.AsSpan().Slice(0, 5).SequenceEqual(array2); Console.WriteLine(isEqual); //Output: FalseIn this example, we have two arrays - array1 and array2. We are using the Slice method to select a range of elements from array1 starting from index 0 and ending at index 4. Then, we are using SequenceEqual method to compare these elements with array2. The output will be false as the selected elements in array1 are not equal to array2. The Slice method is part of the System.Memory package library in C#.