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 |
What is regex c#?
If you define a user defined data type by using the struct keyword, is it a value type or reference type?
What is the purpose of dictionary in c#?
What is difference between il and dll ?
Explain About .NET Remoting and types of remoting
Explain About Virtual functions and their use.
What is the meaning of MSIL?
What is a resource? Provide an example from your recent project.
2 Answers IBM, Logica CMG, Wipro,
What are the types of threading models ?
Why do I get an error (cs1006) when trying to declare a method without specifying a return type?
What is covariance and contravariance? Did Delegate and method overriding support these?
Why is hashset faster?