I’m writing a generic class where I need to use Interlocked.
T test1, test2;
Interlocked.Exchange<T>(ref test1, test2);
This won’t compile. So am I forced to use Exchange(Object, Object) instead even tho MSDN advices not to use it that way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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: