what is reference parameter?
what is out parameters?
what is difference these two?

Answer Posted / dharmendra nonia

A reference parameter contain only reference of variable
instead of value. In reference type parameter if changes
occurs in variable than it affect the original value. But
in out parameter it send only a copy of variable instead of
reference therefore if u change in variable no changes
occur in original value.
For example:-
class Program
{
public void refparameter(ref int a)
{
a += 5;
}
public void outparameter(out int p)
{
p = 20;
}
static void Main(string[] args)
{
Program p = new Program();
int b,c;
Console.Write("Enter a Number:");
b = Int32.Parse(Console.ReadLine());
p.refparameter(ref b);
//After the calling of refparameter it change the value of b
Console.WriteLine("After calling refparameter
method value of B is:{0}",b);
p.outparameter(out c);
Console.WriteLine("After calling the
outparameter method value of C is:{0}",c);
Console.ReadLine();
}
}

Is This Answer Correct ?    6 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can you create sealed abstract class in c#?

481


What is parse method in c#?

452


What is the solution if you need to manipulate sets of items?

466


What is the difference between parse and tryparse in c#?

492


How to generate strong name key file or which command is used to generated strong name key file?

512






What is the default value of boolean variable?

454


Define c# i/o classes? List the commonly used classes?

543


What are the basic string operations? Explain.

510


Define c# i/o classes?

527


Is there an equivalent of exit() for quitting a c# .net application?

491


What is a console device?

480


Explain about WSDL

594


What is data set in c#?

500


Can struct inherit from class c#?

530


What do you understand by an Implicit Variable?

524