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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / satya

if you want pass parameters by reference then ref keyword
should be used in calling and called methods
void add(ref int x)--- called(formal parameter)
add(ref a)-----calling(actual parameter)
.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Interview Questions

Contrast System.String and System.Text.StringBuilder classes?

0 Answers   Siebel,


Can multiple catch blocks be executed?

4 Answers  


What is a type c#?

0 Answers  


What does exclamation mark mean in access query?

0 Answers  


Can you inherit multiple interfaces?

3 Answers  


What are callback methods in c#?

0 Answers  


Explain the advantage of using system.text.stringbuilder over system.string?

0 Answers  


Is null empty or whitespace c#?

0 Answers  


How?s method overriding different from overloading?

3 Answers  


How many types of delegates are there in c#?

0 Answers  


Is a char?

0 Answers  


Which is faster dictionary or hashtable?

0 Answers  


Categories