Here is my current swap code for swapping 2 KeyValuePair objects in an array:
KeyValuePair<int, T> t = a[i]; a[i] = a[j]; a[j] = t; Would there be any speed advantage to using unsafe code and merely swapping the pointers of the 2 objects? Or does the complier effectively boil this safe code down to effectively doing just that?
KeyValuePair<TKey, TValue>is a value type, so those aren't "pointers" in the array; they're the values themselves (each consisting of aTKeyand aTValue) -- though, obviously,TKeyand/orTValuecould be reference types.