System.Threading.AtomicBoolean.Exchange C# (CSharp) Method

Exchange() public method

public Exchange ( bool newVal ) : bool
newVal bool
return bool
		public bool Exchange (bool newVal)
		{
			int newTemp = newVal ? Set : UnSet;
			return AotInterlocked.Exchange (ref flag, newTemp) == Set;
		}

Usage Example

 public void Exchange()
 {
     AtomicBoolean ai = new AtomicBoolean( true );
     Assert.AreEqual(true, ai.Exchange(false));
     Assert.AreEqual(false, ai.Exchange(false));
     Assert.AreEqual(false, ai.Exchange(true));
     Assert.AreEqual( true, ai.Value );
 }