Roslyn: Range indexer on array should probably not be ref-returning

Created on 18 Dec 2018  路  2Comments  路  Source: dotnet/roslyn

The following works:

C# using System; public class C { public void M(int[] arr) { ref int[] x = ref arr[0..2]; } }

But I'm not sure it should.

Area-Compilers Bug

Most helpful comment

馃挱 I would have expected arr[0..2] to produce Span<int>, which is a ref-like type but not ref int[]

All 2 comments

馃挱 I would have expected arr[0..2] to produce Span<int>, which is a ref-like type but not ref int[]

Does the indexer copy the array? That is very surprising to me.

Was this page helpful?
0 / 5 - 0 ratings