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
Is nullable type c#?
How many digits are in an integer?
How can I get around scope problems in a try/catch?
The int maps to which C# keyword in .NET type?
Why do we use anonymous method in c#?
Why singleton is sealed?
What is cookies c#?
What is nameof c#?
What is parameter c#?
What do you mean by winforms in c#?
What is the default value of object in c#?
What is satellite assembly? And steps to create satellite assembly?
What are the variables in c#?
Can you declare a class or a struct as constant?
What is the difference between User controls and Custom Controls?