473,788 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

a bit confused with out and ref keywords

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.
Nov 16 '05 #1
2 1633
Flip <[remove]ph******@hotmai l.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
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.

Nov 16 '05 #3

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

Similar topics

4
4414
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 contents of the page. Ideally, I don't just want to explode the string and remove "and", "or" and "the" etc. because some the the repeated keywords may be more that one word long.
7
13631
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 correctly) as: ------------------------------------------- class Base { public: Base(); }; Base::Base() { printf("Base"); } class Derived : Base { public: Derived(); override; }; Derived::Derived() { /*inherited;*/ printf("Derived"); }
2
2410
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
14
2361
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 entered: #include <iostream> #include "KeyWord.h" int main() { KeyWord word;
5
3058
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 quotes or double quotes can be used and there can be any number of spaces or returns between any element. Keywords can contain special characters except for a comma or a closed bracket. For example, the HTML might be:
36
2547
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 seems that it discusses the std and the other part of the language with your own abstractions. Is that better to read a book first on the basic concepts of C++ language (but not the C part) that gives the basics as if the reader is a beginner...
9
3383
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 information I want, based on keywords mentioned in the needed paper. Since I don't feel like inventing hot water, I thought I'd ask you people a few questions. I was planning on making tables with a many-to-many relationship for papers and...
2
1450
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 in the past. The style sheet includes such things as div#header. Is this correct? I thought it should be either div header or #header. I can't find any reference to this online. Also, the html references two style sheets in addition to the...
2
19905
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 iteration variable'" is the error message I'm getting for code that I think should work. I'm sure that there is some sublety I'm missing... maybe with the use of a reference, or foreach, or template class. Can someone maybe explain it with small words...
5
2661
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 http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(vs.80).aspx but I want to get this list programmatically.
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10177
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10118
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5403
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2897
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.