如何解决有没有办法获取对 C# 数组元素的引用?
我想知道是否有办法在 c# 中获取对数组元素的引用。
类似这样但没有指针的东西:
SomeClass *arr[5];
...
SomeClass** p = &arr[2];
到目前为止我得到了这个:
SomeClass arr[] = new SomeClass[5];
// Put something in the array
SomeClass p = arr[2]; // This will give me the initial object,not the array ref
p = new SomeClass(); // I want the array to now use this new object
解决方法
这不是你想要的吗?
var arr = new SomeClass[5];
ref SomeClass p = ref arr[2];
p = new SomeClass();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。