METHOD

List<T>.Slice

Creates a shallow copy of the requested sublist. Available from .NET 8; with modern C# its Count, indexer and Slice members also enable range syntax such as items[1..3]. The end of a range is exclusive.

Formal Syntax & Structure

csharp syntaxcsharp
items.Slice(start, length)

Working Example

Example Snippetcsharp
using System;using System.Collections.Generic;var items = new List<int> { 1, 2, 3, 4 };Console.WriteLine(string.Join(",", items[1..3])); // 2,3
C# & .NET Reference