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 pass value types by reference to a method?

511


How long can loop recorders stay in?

591


Explain how is the dll hell problem solved in .net?

449


Is it possible to have a static indexer in c#?

537


What Happens In Memory When You Box And Unbox A Value-type?

458






What debugging tools come with the .NET ssSDK?

679


What is a factory in c#?

466


Overloaded constructor will call default constructor internally?

551


Explain manifest & metadata in c#.

521


What's the difference between an integer and int?

521


What are the characteristics of c#?

460


What is binary search tree in data structure?

469


What are delegates and why are they required?

497


Can we change static value in c#?

514


What is the use of regex in c#?

486