C# How do I compare and exchange two structs?

I have the following program:

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);
    }
}

How can I make this compile?

Jon Skeet
people
quotationmark

You can't, basically. The framework doesn't provide a way of performing atomic, lock-free operations on arbitrary structs.

people

See more on this question at Stackoverflow