我相信当普通数组(例如
例如,下面的代码是否依赖于装箱(
int[]
)使用foreach
时,C#编译器会将其重写为for
。但是,对于存储struct
的集合,遍历其内容是否会导致装箱?例如,下面的代码是否依赖于装箱(
IEnumerable<KeyValuePair<int,byte>>
)来迭代dict
的内容?void DoSomething(Dictionary<int,byte> dict) {
foreach(KeyValuePair<int,byte> itr in dict)
m_correlation += itr.Key; }
ildasm
或ilspy
查找生成的程序集中的box
操作码吗? - Gabe