-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: s_hashim
Message 2 in Discussion
out method
The out method
parameter keyword on a method parameter causes a method to refer to the same
variable that was passed into the method. Any changes made to the parameter in
the method will be reflected in that variable when control passes back to the
calling method.
Declaring an out method is useful
when you want a method to return multiple values. A method that uses an out
parameter can still return a value. A method can have more than one out
parameter.
To use an out parameter, the
argument must explicitly be passed to the method as an out argument. The value
of an out argument will not be passed to the out parameter.
A variable passed as an out argument
need not be initialized. However, the out parameter must be assigned a value
before the method returns.
A property is not a variable and
cannot be passed as an out parameter.
An overload will occur if
declarations of two methods differ only in their use of out. However, it is not
possible to define an overload that only differs by ref and out. For example,
the following overload declarations are valid:
class MyClass
{
public void MyMethod(int i) {i = 10;}
public void MyMethod(out
int i) {i = 10;}
}
while the following overload declarations are
invalid:
class MyClass
{
public void MyMethod(out int i) {i = 10;}
public void
MyMethod(ref int i) {i = 10;}
}
ref method
The ref method parameter keyword on a method parameter causes a method to
refer to the same variable that was passed into the method. Any changes made to
the parameter in the method will be reflected in that variable when control
passes back to the calling method.
To use a ref parameter, the argument must explicitly be passed to the
method as a ref argument. The value of a ref argument will be passed to the ref
parameter.
An argument passed to a ref parameter must first be initialized. Compare
this to an out parameter, whose argument does not have to be explicitly
initialized before being passed to an out parameter.
A property is not a variable and cannot be passed as a ref parameter.
An overload will occur if declarations of two methods differ only in their
use of ref. However, it is not possible to define an overload that only differs
by ref and out. For example, the following overload declarations are
valid:
class MyClass
{
public void MyMethod(int i) {i =
10;}
public void MyMethod(ref int i) {i = 10;}
}
but the
following overload declarations are invalid:
class MyClass
{
public void MyMethod(out int i) {i =
10;}
public void MyMethod(ref int i) {i =
10;}
}
**********
Keep Smiling,
Regards.
Sayad Hashim Ali Kazi
Microsoft India
Community Star.
*************************
SQL Star International Ltd.
SQL House, #13,Infocity,Madhapur,
Hyderabad 500 081.
Tel: +91-40-2310 1650(Off) +91-40-55683272(Resi)
http://dotnetjunkies.com/WebLog/SayadHashim/
http://SayadHashim.blogspot.com
http://www.mugh.net
***************************
-----Original Message-----
From: mag_mani
[mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 03,
2004 11:27 AM
To: BDOTNET
Subject: ref vs
out
New Message on BDOTNET
ref vs
out
Reply
Reply to Sender Recommend
Message 1 in
Discussion
From: mag_mani
Hi
Whats the exact difference between ref and out method
parameter in c#. In which case ref or out should be
used.
Magesh
View other groups in this
category.
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]