我有一个声明为的类public class DatumSet : List<datum>
,其中
public struct datum {
public UInt32[] chan;
public UInt64 sample_number;
public float time;
public UInt32 source_sector;
}
我想遍历列表并进行一些更改。为什么这不起作用
for (int i = 0; i < this.Count; i++) {
this[i].sample_number = startSample;
this[i].time = (float)startSample / _sample_rate;
startSample++;
}
但这确实有效
for (int i = 0; i < this.Count; i++) {
datum d = this[i];
d.sample_number = sampleNumber;
d.time = (float)sampleNumber / _sample_rate;
sampleNumber++;
}
我得到错误:
无法修改“System.Collections.Generic.List.this[int]”的返回值,因为它不是变量