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

What is regex c#?

0 Answers  


If you define a user defined data type by using the struct keyword, is it a value type or reference type?

0 Answers  


What is the purpose of dictionary in c#?

0 Answers  


What is difference between il and dll ?

0 Answers  


Explain About .NET Remoting and types of remoting

0 Answers  






Explain About Virtual functions and their use.

0 Answers  


What is the meaning of MSIL?

0 Answers   TCS,


What is a resource? Provide an example from your recent project.

2 Answers   IBM, Logica CMG, Wipro,


What are the types of threading models ?

4 Answers   Digital GlobalSoft,


Why do I get an error (cs1006) when trying to declare a method without specifying a return type?

0 Answers  


What is covariance and contravariance? Did Delegate and method overriding support these?

1 Answers   TCS,


Why is hashset faster?

0 Answers  


Categories