我有以下程序:
public class Program
{
struct Foo
{
public int Bar;
public int Zoo;
}
public static void Main()
{
Foo a;
Foo b;
a.Bar = 5;
a.Zoo = 2;
b.Bar = 5;
a.Zoo = 2;
Foo c;
c.Bar = 3;
c.Zoo = 5;
var result = Interlocked.CompareExchange(ref a, b, c);
}
}
如何编译?
最佳答案
基本上,你不能。该框架不提供对任意结构执行原子、无锁操作的方法。
关于C# 如何比较和交换两个结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35160448/