Re: Passing arguements by reference



Mark R. Dawson <MarkRDawson@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I understood everything upto the code above, You say its passed by
reference, but doSomething doesnt change p unless i use "ref"? Surely
that is by value then? :-/

The subtle point to note is that the underlying object is passed by
reference, hence both p and q pointing to the same object, not to different
object BUT the actual variable which points to the object is copied when you
don't use the ref keyword.

Passing a reference by value *isn't* passing an object by reference.
It's similar, I admit - but there are very specific meanings for the
teams, and they're not the same thing.

(This is compounded by the fact that no expression is actually an
object in C#.)

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: Why are get/set properties useful?
    ... passing reference objects to functions, ... ref PricingConditionTable, ... add/remove accessors around them, which is, after all, pretty much the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Pass by reference vs Pass by Value (is data aliasing a problem in C#?)
    ... keyword ref is able to do, using passing-ref-by-value, rather than ... using keyword 'ref' and passing-ref-by-reference, ... How would you implement int.TryParsewithout passing by reference? ... Usually you don't need to pass by reference, and so that's why usually passing by reference isn't done. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Passing arguements by reference
    ... but doSomething doesnt change p unless i use "ref"? ... reference, hence both p and q pointing to the same object, not to different ... don't use the ref keyword. ... void Execute() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: how to use List Class in Base class?
    ... If I don't pass by ref and pass the instance of the class to ... Reference types are already a reference to an object allocated ... Passing a reference type as is (i.e. ... you'd be passing a pointer to a pointer to an instance. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Documentation suggestions
    ... > Ian> I think it would be very useful if there was reference (not just ... Lang ref as only for "language lawyers". ...
    (comp.lang.python)