473,404 Members | 2,137 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,404 software developers and data experts.

Differences between the ref and out keyword ?

Hello

I'm wondering what is exactly the difference between "ref" and "out"
keywords.

Thanks,
Steve
Nov 16 '05 #1
4 13774
Ref parameter Should be initilized before call.
Out need not to initilized before call.

Ref paramenter is nothing but in & out parameter.
Out is only out parameter.

There is no performance issue occured.

A ref or out argument must be an lvalue.ie, you need to pass the
same
signature.The casting is not allowed for both when you pass the
values to ref/out.
ex.
public void Test(ref int a, out int b)
{
a=100;
b=200;
}

public void Caller()
{
int a,b;
a=10; //If you miss init it will give
error.
Test(ref a,out b);

object x=10,y;
Test(ref (int)x,out (int)y); // It is
not Allowed.Bcs it is not lValue.
}
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"Steve B." <st***************@airsoftconsulting.com> wrote in message
news:41**********************@news.free.fr...
Hello

I'm wondering what is exactly the difference between "ref" and "out"
keywords.

Thanks,
Steve

Nov 16 '05 #2
thx :)

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> a écrit dans le message de
news:eo**************@tk2msftngp13.phx.gbl...
Ref parameter Should be initilized before call.
Out need not to initilized before call.

Ref paramenter is nothing but in & out parameter.
Out is only out parameter.

There is no performance issue occured.

A ref or out argument must be an lvalue.ie, you need to pass the
same
signature.The casting is not allowed for both when you pass the
values to ref/out.
ex.
public void Test(ref int a, out int b)
{
a=100;
b=200;
}

public void Caller()
{
int a,b;
a=10; //If you miss init it will give
error.
Test(ref a,out b);

object x=10,y;
Test(ref (int)x,out (int)y); // It is
not Allowed.Bcs it is not lValue.
}
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"Steve B." <st***************@airsoftconsulting.com> wrote in message
news:41**********************@news.free.fr...
Hello

I'm wondering what is exactly the difference between "ref" and "out"
keywords.

Thanks,
Steve


Nov 16 '05 #3
Hi Steve:

See Jon's article:

Parameter passing in C#
http://www.yoda.arachsys.com/csharp/parameters.html

--
Scott
http://www.OdeToCode.com

On Thu, 29 Jul 2004 15:33:52 +0200, "Steve B."
<st***************@airsoftconsulting.com> wrote:
Hello

I'm wondering what is exactly the difference between "ref" and "out"
keywords.

Thanks,
Steve


Nov 16 '05 #4
C Addison Ritchie <CA*************@discussions.microsoft.com> wrote:
"ref" and "out" are very similar with the exception that the initial
value of the "out" parameter provided by the caller is unimportant.


Not only is it unimportant - it doesn't even have to be definitely
assigned. However, every normal exit of a method with an "out"
parameter *does* have to make sure it will be definitely assigned by
that point.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5

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

Similar topics

4
by: MS | last post by:
Just a general question here re VBA. Can anyone explain the differences between "!" and "." when refering to a control? eg Me!TxtBox and Me.TxtBox. What is difference between "+" and "&"...
28
by: Skybuck Flying | last post by:
Hi, I think I understand now a bit better what the difference is between a c compiler and a pascal compiler. For example: When compiling source code with a pascal compiler. The pascal...
6
by: n_o_s_p_a__m | last post by:
Ok, here is a dumb one: Is there any difference between the lines new object() and new Object()
1
by: superfrog | last post by:
Hi there, while trying to learn polymorphism, i am confused between the 2. ======================================================= class Person { ...
16
by: RdS | last post by:
Hello Would someone tell me the differences between following statements? When would you use one over the other? dim objtest1 as car dim objtest2 as new car dim objtest3 as car = new car ...
5
by: Scott M. | last post by:
Why will this fail: (short) txtQty.Text and this succeed? Convert.ToInt16(txtQty.Text)
11
by: blangela | last post by:
I am teaching a C programming course to C++ programmers and want to come up with list of _KEY_ differences between the two languages. Below is a list I have come up with so far. Have I missed any?...
3
by: gentsquash | last post by:
Inside of <script></script>, inside of <body></body>, what are the differences between document.body.className="mystyle"; and document.body.setAttribute("class", "mystyle"); ? (...assuming...
21
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
1
by: alamodgal | last post by:
hiiiiiii I have a problem in highlighting searching keyword.Actually im using this function for searching Public Function HighLight(ByVal Keyword As String, ByVal ContentFor As String) Dim...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
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
Oralloy
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,...
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
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...
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.