是否可以从List <T>访问结构的引用.进行更改? [英] Is it possible to access a reference of a struct from a List<T> to make changes?
本文介绍了是否可以从List <T>访问结构的引用.进行更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个放置在List<T>
中的结构,我想在该结构中的某个特定位置编辑一些值.无需复制结构,编辑副本并替换列表中的条目,这是否完全可能?
I have a struct which I put in a List<T>
, I want to edit some value in that struct at a specific position. Is this at all possible without making a copy of the struct, editing the copy, and replacing the entry in the List?
推荐答案
否,要执行此操作,您需要引用List
/IList
未提供的内部数组元素.
No, to be able to do it you need reference to element of inner array which is not provided by List
/IList
.
如果需要,可以使用不安全的代码和数组来实现.
You can do that with unsafe code and arrays if you have to.
这篇关于是否可以从List <T>访问结构的引用.进行更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文