我处于迭代多个记录并根据这些记录中的数据设置状态信息的情况。像这样的东西(不是真正的代码,只是一个简化):
StateObject state;
ConcurrentQueue<Record> records;
while(!records.IsEmpty())
{
//set state here based on the next record
}
那么,这样做会更有效/更好的做法吗?
{
//set state here based on the next record
Record r = records.next();
state = r.state;
}
或者
{
//set state here based on the next record
Record r = records.next();
if(state != r.state)
state = r.state;
}