Tech Off Post

Single Post Permalink

View Thread: differnence between Ref and Out
  • User profile image

    In C#, ref and out are the same, except that if you use out, the called method is required to initialize the value before it can return.

    Use out if the called method doesn't care about the parameter's initial value, and use ref if you want to pass a value both in (the called method actually uses the value) and out (the calling method wants to use the updated value).

    In neither case is the value boxed/unboxed. Internally it merely uses a pointer to the value instead of passing it by value (just like passing by ref in C++).