using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.ComponentModel; public class MyClass { public void M1() { var y = 4; int[] x1 = [1 + 4, 2, 8]; Span x2 = [3, y]; int[] all = [.. x1, .. x2]; int[][] jagged = [[1, y], x1]; int[] nested = [1, .. (int[])[.. x1]]; IntegerCollection collection = [4, y, 9, .. x1]; M2([1, 2, 3]); } public static void M2(Span x) { } public static void M2(ReadOnlySpan x) { } } [System.Runtime.CompilerServices.CollectionBuilder(typeof(IntegerCollectionBuilder), "Create")] public class IntegerCollection : IEnumerable { private int[] items; public IntegerCollection(ReadOnlySpan items) { this.items = items.ToArray(); } public IEnumerator GetEnumerator() => items.AsEnumerable().GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => items.GetEnumerator(); } public static class IntegerCollectionBuilder { public static IntegerCollection Create(ReadOnlySpan elements) => new IntegerCollection(elements); }