rem*_*dao 3 c# generics interlocked
我正在编写一个通用类,我需要使用Interlocked.
T test1, test2;
Interlocked.Exchange<T>(ref test1, test2);
Run Code Online (Sandbox Code Playgroud)
这不会编译.所以我被迫使用Exchange(对象,对象)而不是MSDN建议不要那样使用它?
Ree*_*sey 10
This will work, provided your generic class has the same constraints as Interlocked.Exchange<T>
, namely, where T: class
.
From the docs for Interlocked.Exchange:
This method only supports reference types