Maybe I'm reading too much, I'm sorry if this is a very newbie question.
I'm reading the OReilly's Programming C# book, and it talks about ref and
out, cool. I thought I understood you have out on the outgoing and ref on
the accepting method side. But now I'm reading a webpage from another
posting ( http://www.yoda.arachsys.com/csharp/parameters.html), that has the
out (or ref) on the method call and on the method declaration. HUH? I
thought I understood it before, now I think I understand it better (from the
webpage), but there is still use use case of mixing the out and ref
together. Can anyone clear up this confusion? Thanks. 2 1618
Flip <[remove]ph******@hotmail.com> wrote: Maybe I'm reading too much, I'm sorry if this is a very newbie question.
I'm reading the OReilly's Programming C# book, and it talks about ref and out, cool. I thought I understood you have out on the outgoing and ref on the accepting method side.
No. They're different modifiers.
But now I'm reading a webpage from another posting (http://www.yoda.arachsys.com/csharp/parameters.html), that has the out (or ref) on the method call and on the method declaration.
Yes. You need to specify it on both the call and the declaration, and
they must be the same in both places.
HUH? I thought I understood it before, now I think I understand it better (from the webpage), but there is still use use case of mixing the out and ref together. Can anyone clear up this confusion? Thanks.
Out and ref are different modifiers. They're very similar - the
differences are in terms of "definite assignment". I'm not sure I can
spell the differences out better than I did on the page: http://www.yoda.arachsys.com/csharp/parameters.html#out
If the O'Reilly book really says you need out in one place and ref in
the other, it's talking rubbish.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Hi Flip,
Use "out" (output) paramater if you want to set its value in
method's body, e.g.:
void GetLocation(out int x, out int y, Point p) {
x=p.X;
y=p.Y;
}
Use "ref" (reference) parameter if you want to get and set its
value in method's body, e.g.:
void Increment(ref int i, int step) {
i=(i+step);
}
HTH
Marcin Maybe I'm reading too much, I'm sorry if this is a very newbie question.
I'm reading the OReilly's Programming C# book, and it talks about ref and out, cool. I thought I understood you have out on the outgoing and ref on the accepting method side. But now I'm reading a webpage from another posting (http://www.yoda.arachsys.com/csharp/parameters.html), that has the out (or ref) on the method call and on the method declaration. HUH? I thought I understood it before, now I think I understand it better (from the webpage), but there is still use use case of mixing the out and ref together. Can anyone clear up this confusion? Thanks.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nel |
last post by:
Hi all,
Before I re-invent the wheel here, has anyone willing to share a basic
script to extract META keywords from a string. I have a string, let's say
$pageText that contains the dynamic...
|
by: Beach Potato |
last post by:
I guess I've been out of C++ for a while, since right now I don't seem
to get a simple solution for overriding inherited constrictors.
What worked in Borland C++ & Pascal (and Java, if I remember...
|
by: Cherry |
last post by:
I have a trigger that won't compile:
CREATE OR REPLACE TRIGGER TRG_CORRESPONDENCE_UPT
AFTER UPDATE
on TBLCORRESPONDENCE
for each row
BEGIN
IF :OLD.Keywords <> :NEW.Keywords THEN
|
by: Jason Heyes |
last post by:
I want to write a class that supports operations on keywords belonging to
the C++ programming language. The following program repeatedly prompts the
user for a keyword until 'explicit' is finally...
|
by: Digital.Rebel.18 |
last post by:
I'm trying to figure out how to extract the keywords from an HTML
document.
The input string would typically look like:
<meta name='keywords' content='word1, more stuff, etc'>
Either single...
|
by: utab |
last post by:
Dear,
I have experince in C( numerical projects, like engineering problems,
scientific applications) I have the basic notion of C++ also, I have
read Accelerated C++ until Chapter 7, however it...
|
by: Nenad Loncarevic |
last post by:
I am a geologist, and over the years I've accumulated quite a number
of proffesional papers on the subject, in various publications. I
would like to make a database that would help me find the...
|
by: wavedancer |
last post by:
I am confused about the syntax used in the style sheet that accompanies the website I've inherited and have been asked to tidy up. XHTML is new to me, and I've only used CSS for font and link styles...
|
by: John Kelsey |
last post by:
I am an old, longtime C programmer surprised and confused by an error
message I'm getting from my VS2005 compiler...
"Cannot pass 'Item' as a ref or out argument because it is a 'foreach...
|
by: =?Utf-8?B?UGV0ZXI=?= |
last post by:
How can I get the list of connection string's keywords available in sqlclient
programmatically? I have found the list in here...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
| |