what is used ref keyword in c#,and how we used it?
Answers were Sorted based on User's Feedback
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 |
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 |
Contrast System.String and System.Text.StringBuilder classes?
Can multiple catch blocks be executed?
What is a type c#?
What does exclamation mark mean in access query?
Can you inherit multiple interfaces?
What are callback methods in c#?
Explain the advantage of using system.text.stringbuilder over system.string?
Is null empty or whitespace c#?
How?s method overriding different from overloading?
How many types of delegates are there in c#?
Is a char?
Which is faster dictionary or hashtable?