C# 传递具有特定数组索引的数组
我想将数组传递到C#中具有特定索引的函数,就像我们在C ++中一样,类似以下内容:
void foo(int* B) {
// do something;
}
int main() {
int A[10];
foo(A + 3);
}
在这种情况下,假设a
以基础地址1000
,然后b为1000+(sizeof(int)*3)
。此 link 使用 skip()
函数调用,但在这种情况下,b
应该是类型iEnumerable< int>
以及在调用skip()
skip()代码>带有toArray()
它创建一个具有不同基本地址的副本,但我想将同一数组传递给function foo。我们如何在C#中做到这一点?
I want to pass an array to a function with specific index in C#, like we do in C++, something like below:
void foo(int* B) {
// do something;
}
int main() {
int A[10];
foo(A + 3);
}
In this case suppose A
starts with base address 1000
, then B would be 1000+(sizeof(int)*3)
. The answer in this link uses Skip()
function call but in this case B
should be of type IEnumerable<int>
and on calling Skip()
with ToArray()
it creates a copy with different base address, but I want to pass this same array to function foo. How can we do that in C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这在这里得到了回答:
C# Array slice without copy
You can use ArraySegment or Span to achieve this
This has been answered here:
C# Array slice without copy
You can use ArraySegment or Span to achieve this