kor*_*inp 8 c# range multidimensional-array
在 C# 8.0 中,为什么我可以在一维数组上使用 range:
var oneDim = new int[5];
var oneDimSlice = oneDim[2..4];
Run Code Online (Sandbox Code Playgroud)
但是不能在多维数组上使用它?
var twoDim = new int[5, 5];
var twoDimSlice = twoDim[2..4, 2..4];
Run Code Online (Sandbox Code Playgroud)
https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/ranges-indexes
Array 有更细微的行为。一维数组同时支持索引和范围。多维数组没有。多维数组的索引器有多个参数,而不是单个参数。锯齿状数组,也称为数组数组,支持范围和索引器。
所以答案是否定的,但如果您有兴趣,可以使用锯齿状数组来完成。