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 you mean by inner exception in c#?
What is lock statement in C#?
how to sort an array in c#
Which are the access modifiers available in c#?
What are the valid parameter types we can pass in an Indexer ?
What is the use of giving more than one CATCH BLOCK in one TRY block? Directly we can give that catch(Exception e)?Why we go for arrayoutofbound Exception,divided by zero etc..? Explain
Is lazy thread safe c#?
Are arrays immutable c#?
What are Regex / regular expressions ?
What is the difference between dynamic type variables and object type variables in c#?
List some of the classes used by system.data namespace?
What is the purpose of a constructor in c#?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)