这个问题在这里已经有答案了
:
C#中的数组切片
(19个答案)
什么是“span”?我应该在什么时候使用它?
(2个答案)
昨天关门了。
int []arr = new int[4];
arr[^1]; // returns the last element
我正在尝试弄清楚上面的语法。它返回最后一个元素,但是为什么呢?
发布于 2021-03-01 14:53:44
C# 8.0及以后的版本中,声明了
新的范围和索引
其中,
运算符:
让我们从索引的规则开始。考虑一个数组序列。The The The
索引与
..。The The The
索引与
..。
因此,这是一种反向搜索可索引对象的方法,而不需要像这样迭代
..。
string[] words = new string[]
{
// index from start index from end
"The", // 0 ^9
"quick", // 1 ^8
"brown", // 2 ^7
"fox", // 3 ^6
"jumped", // 4 ^5
"over", // 5 ^4
"the", // 6 ^3
"lazy", // 7 ^2
"dog" // 8 ^1
}; // 9 (or words.Length) ^0
https://stackoverflow.com/questions/66417774
复制相似问题