canton7's answer is correct, and thanks for the shout-out. I'd like to add a few additional points.
This sentence, as is too often the case in the .NET documentation, both chooses to enstructure bizarre word usements, and thoroughly misses the point. For me, the poor word choice that stood out was not "late bound", which merely misses the point. The really awful word choice is using "destination object" to mean variable. A variable is not an object, any more than your sock drawer is a pair of socks. A variable contains a reference to an object, just as a sock drawer contains socks, and those two things should not be confused.
As you note, the reason to prefer the T
version has nothing to do with late binding. The reason to prefer the T
version is C# does not allow variant conversions on ref
arguments. If you have a variable shelly
of type Turtle
, you cannot pass ref shelly
to a method that takes ref object
, because that method could write a Tiger
into a ref object
.
What then are the logical consequences of using the Object
-taking overload on shelly
? There are only two possibilities:
- We copy the value of
shelly
to a second variable of type Object
, do the exchange, and then copy the new value back, and now our operation is no longer atomic, which was the whole point of calling the interlocked exchange.
- We change
shelly
to be of type Object
, and now we are in a non-statically-typed and therefore bug-prone world, where we cannot ever be sure that shelly
still contains a reference to Turtle
.
Since both of those alternatives are terrible, you should use the generic version because it allows the aliased variable to be of the correct type throughout the operation.