Can we return two values from a function?
Answers were Sorted based on User's Feedback
Answer / dumb_dumb
Function always returns only one return value.
In other word, function cannot have a multiple return value.
The out or ref parameter can be used to trick the problem. However the return value still only one since Even the void function/method return 'null' value.
| Is This Answer Correct ? | 13 Yes | 0 No |
Answer / abhinav kashyap
Using return statment, it is not possible to return more
than one value but if we use the Out parameters then we can
have return more than one value depanding upon how many
parameters u have given as Out Parameter.
| Is This Answer Correct ? | 6 Yes | 1 No |
Answer / srinivas.r
Function should have only one return statement,whereas
using out parameter its possible to send more than on value.
| Is This Answer Correct ? | 4 Yes | 0 No |
Answer / vinay tiwari
with the help of out paraeter we can return two value from
function
| Is This Answer Correct ? | 4 Yes | 1 No |
Answer / tarun kumar
yes.
for example:
public int Add(int a,int b,out int c)
{
c=a+1;
return a+b;
}
when we call the Add method we will get the sum of the a
and b and can also use the value of c
like
int d=0;
int e= Add(2,3,d) ;
then the value of e will be 5 and the value of d will be 3.
| Is This Answer Correct ? | 9 Yes | 8 No |
Answer / ish rastogi
in c# a function can return two values with the help of out
parameter.
| Is This Answer Correct ? | 3 Yes | 2 No |
Answer / vijay
yes we can return two values with the help of out keyword
| Is This Answer Correct ? | 4 Yes | 4 No |
Answer / niks
I think yes.. Function can return multiple values.. It's
not good practice.. but C# allows you.. Consider following
example
int Val;
GetValue(Val);
bool GetValue(out int Val)
{
Val = value;
return true;
}
| Is This Answer Correct ? | 4 Yes | 5 No |
Guys, you will be able to return n number of values, while
you are using arraylist.
| Is This Answer Correct ? | 6 Yes | 9 No |
Answer / vijay saxena
No
only one value will return at a time but function may have
multiple output statement ..
| Is This Answer Correct ? | 1 Yes | 7 No |
what is the difference between .dll and .exe
Can we override constructor in c#?
What is public, private, protected, internal and internal protected?
What is a thread c#?
Does the variables of a private class-level inherited?
main concept of c sharp
Is lazy thread safe c#?
Why is c# a good programming language?
What is lazy loading entity framework?
Is boxing an implicit conversion?
What is the namespcae generally given to the webpage of the .NET Framework ?
What is selector 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)