以下代码
using System.Threading;
class Test
{
volatile int counter = 0;
public void Increment()
{
Interlocked.Increment(ref counter);
}
}
引发以下编译器警告:
"A reference to a volatile field will not be treated as volatile"
我在这里做错了什么导致出现了这个警告?为什么编译器要警告我?