Reputation: 3672
Are local variables always volatile in C#?
In other words, is the volatility of num
the same in these two classes:
public sealed class ThreadSafeObjectA
{
private volatile int num;
public int DoThing() => num = 1;
}
public sealed class ThreadSafeObjectB
{
public ThreadSafeObjectB()
{
var num = 0;
DoThing = () => num = 1;
}
public readonly Func<int> DoThing;
}
Upvotes: 0
Views: 56