473,396 Members | 2,089 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Form constructor taking parameters by reference

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?

--
"Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams"
Jan 15 '07 #1
7 2113
Hi,

"Nikola Skoric" <ni*******@net4u.hrwrote in message
news:MP************************@news.t-com.hr...
|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
--
Ignacio Machin
machin AT laceupsolutions com
Jan 15 '07 #2
Nikola Skoric <ni*******@net4u.hrwrote:
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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 15 '07 #3
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

Jan 15 '07 #4
<laughsOK: 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

Jan 15 '07 #5
Marc Gravell <ma**********@gmail.comwrote:
<laughsOK: 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...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 15 '07 #6
In article <MP************************@msnews.microsoft.com >,
sk***@pobox.com says...
Nikola Skoric <ni*******@net4u.hrwrote:
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
10 points for Jon. Thanks a bunch, you made my day. :-) Your article now
has another dedicated follower ;-)

--
"Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams"
Jan 15 '07 #7
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
--
Ignacio Machin
machin AT laceupsolutions com
Jan 16 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jared | last post by:
Hi Does anyone know how could I load a form from another and send some parameters to it? Is there a way to identify by name instances of same form? Thx
2
by: VM | last post by:
I have a Windows form that may be called with two parameters or three parameters (depending on who's invoking the form). The form was programmed so it received three parameters. How can I create an...
2
by: sklett | last post by:
I have a Form that I want to show a user to choose some options. I have set it up so that Form's ctor takes ref parameters, one of them is an enum. For example: <code> public enum...
4
by: zazu | last post by:
I have followed the procedure for creating a form for supplying parameters to a query – http://office.microsoft.com/en-us/assistance/HA011170771033.aspx However when the query is run I still...
4
by: Morgan Cheng | last post by:
I am writing a very simple Win Form app. One PictureBox (named ViewPicBox) in the main form (named ViewForm). In the constructor of ViewForm, I set the Image property of ViewPicBox. ViewForm()...
1
by: KhoaNguyen | last post by:
i have two classes..one is a base and the other is inherited from the base class Below is my code -------ConnectionProvider class--------------------- using System; using...
0
Shashi Sadasivan
by: Shashi Sadasivan | last post by:
Hi, I converted some of my form functions as a user control, and it has to work based on a tables specified row (which ispassed to it using the parameter in the constructor) So i make the...
0
by: Lextendo | last post by:
Hi, This is what I want to achieve: I hav a lookup-form used by different parent forms to present a database table. So form X uses the lookup to search table tblA, form Y uses the lookup to...
3
by: raylopez99 | last post by:
Oh, I know, I should have provided complete code in console mode form. But for the rest of you (sorry Jon, just kidding) I have an example of why, once again, you must pick the correct entry point...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.