我试图在for循环中添加一个列表。指数超出范围。必须是非负数,并且小于集合的大小
这里是我的代码 我创建了一个属性在这里
public class SampleItem
{
public int Id { get; set; }
public string StringValue { get; set; }
}
我想从另一个列表中
List<SampleItem> sampleItem = new List<SampleItem>(); // Error: Index out of range
for (int i = 0; i < otherListItem.Count; i++)
{
sampleItem[i].Id = otherListItem[i].Id;
sampleItem[i].StringValue = otherListItem[i].Name;
}
增值有人可以纠正我的代码,请。
哇!多谢你们。只有一分钟,我得到了8个回应!这就是我喜欢这个地方的原因!我试过了,它的作用就像魅力:) – HardCode