Sandeep Banerjee
Can a method Return More than one Value?
Posted by Sandeep Banerjee in C# Programming on Sep 16, 2014
2
10
1422
Do you know the answer for this question? Post it below.
Rahul
Anoop Kumar Sharma
Posted by Anoop Kumar Sharma on Sep 25, 2014
3
Usually Method returns only one value at a time. But in some situation C# Program required to return more than one value from a single method. In Such situation, we have to use Out parameter. Declaring an out parameter in a method is useful when you want a method to return multiple values.
For more visit: http://msdn.microsoft.com/en-us/library/t3c3bfhx.aspx
Kml Surani
Posted by Kml Surani on Apr 15, 2015
0
No, Method Return Only one value
Abrar Ahmad Ansari
Posted by Abrar Ahmad Ansari on Mar 10, 2015
0
Yes you can return more then one value--> use Tuple Concept.
while using below code remove "" quotation from below method return type
class Program
{
public Tuple<"string, int, string> ReturnMorethenOneValue()
{
return new Tuple<"string, int, string>("Abrar Ahmad Ansari", 25, "Bangalore");
}
static void Main(string[] args)
{
var obj = new Program().ReturnMorethenOneValue();
Console.WriteLine("Name :" + obj.Item1);
Console.WriteLine("Age :" + obj.Item2);
Console.WriteLine("Address :" + obj.Item3);
}
}
Pankaj Kumar Choudhary
Posted by Pankaj Kumar Choudhary on Feb 21, 2015
0
Yes,We can do using Out Parameters Like:
static public int Call(out int A1, out int A2, out int A3, out int A4)
{
A1 = 100;
A2 = 200;
A3 = 300;
A4 = 400;
return 500;
}
static void Main(string[] args)
{
int A, B, C, D,E;
E = Call( out A,out B, out C,out D);
Console.WriteLine("A= {0}", A);
Console.WriteLine("B= {0}", B);
Console.WriteLine("C= {0}", C);
Console.WriteLine("D= {0}", D);
Console.WriteLine("E= {0}", E);
Console.ReadKey();
}