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 the difference between interface and functional interface?

0 Answers  


What is the difference between properties and indexer in c#?

0 Answers  


What?s an abstract clas?

5 Answers   Mind Tree,


how to implement a web service in .net

0 Answers  


code for arranging given number in possible permutation ways ex:123,321,312,132,231,213.

0 Answers  






What is indexer c#?

0 Answers  


Explain the concepts of cts and cls(common language specification).

0 Answers  


What are jagged arrays used for?

0 Answers  


Describe how a .net application is compiled and executed

0 Answers  


Name which controls do not have events?

0 Answers  


Give examples for value types?

0 Answers  


7. C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write?

2 Answers  


Categories