我可以像在当前代码中描述的那样使用它吗?
private void Increment() {
lock(LockObject) {
// edit
// ListOfObjects.Add(someInfo);
// new edit ---> here
ListOfObjects.Add(new SomeInfoObject() {
Account = Interlocked.Increment(ref result),
// ... other properties
}
// Interlocked.Increment(ref result);
}
}