Form constructor taking parameters by reference

  • Thread starter Thread starter Nikola Skoric
  • Start date Start date
N

Nikola Skoric

I noticed that System.Windows.Forms.Form constructor treats his
parameters as though they are passed by reference even if I omit the
"ref" keyword. Why's (and how does he do) that? Shouldn't objects be
passed by value if I don't explicitly put "ref" in parameter list?
 
Nikola Skoric said:
I noticed that System.Windows.Forms.Form constructor treats his
parameters as though they are passed by reference even if I omit the
"ref" keyword. Why's (and how does he do) that? Shouldn't objects be
passed by value if I don't explicitly put "ref" in parameter list?

I suspect you're slightly confused about pass by reference semantics vs
"pass reference by value" semantics. Don't worry - lots of people often
are, and it's easy to fix :)

See http://www.pobox.com/~skeet/csharp/parameters.html
 
Hi,

|I noticed that System.Windows.Forms.Form constructor treats his
| parameters as though they are passed by reference even if I omit the
| "ref" keyword. Why's (and how does he do) that? Shouldn't objects be
| passed by value if I don't explicitly put "ref" in parameter list?

IIRC the form constructor by default takes no parameters.

If you have doubt regarding parameters take a look at Jon Skeet's article at
http://www.pobox.com/~skeet/csharp/parameters.html
 
Well, System.Windows.Forms.Form only has a parameterless constructor...
did you mean something else? However, this question probably relates to
value/reference *types* rather than value/reference *passing*; if a
reference-type is passed to a (non-ref) parameter, then the *variable*
is passed by value, but the underlying object is still a single
instance with a shared reference. Jon has a good explanation:
http://www.yoda.arachsys.com/csharp/parameters.html

Marc
 
<laughs> OK: we're in agreement; Mr. Skeet's article gets it;

and Jon: sorry I keep posting arachsys rather than pobox, but the
simple fact is that google always gives me that one first... perhaps
redirect?

Marc
 
Marc Gravell said:
<laughs> OK: we're in agreement; Mr. Skeet's article gets it;

LOL :)
and Jon: sorry I keep posting arachsys rather than pobox, but the
simple fact is that google always gives me that one first... perhaps
redirect?

pobox.com is a redirector service - if I ever change from
yoda.arachsys.com to somewhere else, the pobox addresses should still
work. It's unlikely to happen any time in the near future though...
 
Hi,


|
| pobox.com is a redirector service - if I ever change from
| yoda.arachsys.com to somewhere else, the pobox addresses should still
| work. It's unlikely to happen any time in the near future though...
|

Sorry Jon, you are not allowed to change the domain, not in this lifetime :)
, too many posts linked to it, if you do move it the C# universe will
collapse :D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top