If the expression “c” is a class type, the operator “C” is equivalent to creating a new temporary variable of this type, initialized by the expression “C” and preceding each leading “.”. with this variable. However, if this is a type of structure, things get more complicated. Consider the code (obviously, not the way something is usually written, but written to make a point:
With MyPoints (N) 'Array of Point
N = SomeNewValue
.X = MyPoints (N) .X
.Y = MyPoints (N) .Y
End with
The C operator effectively captures a link to MyPoints (N). Even if MyPoints is changed to some other array, or N is changed, the anchor link will still point to the same element of the same array as when executing the With statement. If you declare a local variable P of type Point and capture MyPoints (N), and then write to PX and PY, the records will only get into the local copy of P, and not update the array. To achieve similar semantics in C #, you had to either use local variables for storage as MyPoints and N, or place the contents of the With statement in an anonymous function with the ref parameter of type Point. To avoid creating a closure at runtime, the anonymous function should also accept, possibly by reference, any local variables that it needs from the outer scope.
supercat
source share