what is used ref keyword in c#,and how we used it?

Answer Posted / raj093300

ref keyword casues an argument to be passed by reference,not
by value.The effect of passing by reference is that any
change to the parameter in the method is reflected in
undergoing argument variable in the calling argument.The
value of a reference parameter is always the same as the
value of the underlying argument variable...

AS SHOWN IN THIS EXAMPLE...

class sample
{
public static int value(ref int a)
{
a=100;
return a;
}
static void Main()
{
int b=22;
int c=value(ref b);
Console.WriteLine("Output was " +c);
Console.Readkey();
}
}

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can a constructor be static in c#?

513


Why dictionary is faster than list?

549


Why can't we use a static class instead of singleton?

445


Can a struct inherit from an interface in c#?

508


What are the types of comment in c# with examples?

477






Illustrate serialization?

506


Why do we use dataset in c#?

477


What are the Types of instancing properties and explain each. Explain the difference between multiuse,singleuse and globalmultiuse and which is default

550


What is the difference between a variable and a literal?

530


What is querystring in c#?

482


How to find methods of a assembly file (not using ILDASM)?

632


What is the advantage of extension method in c#?

455


What is a partial method?

490


What is Inheritance in C#?

570


What is action c#?

482