-
interlock exchange issue
Hello everyone,
How to fix the compile error when interlock exchange a bool type variable?
Code:
public static void Main()
{
bool b = false;
// error CS0452: The type 'bool' must be a reference type in order to use it as parameter
// 'T' in the generic type or method 'System.Threading.Interlocked.Exchange<T>(ref T, T)'
bool a = Interlocked.Exchange(ref b, true);
return;
}
thanks in advance,
George
-
The MSDN examples state that you should be using an int instead. While this is also a non-referencetype, there are overloads of Exchange for int.