Sandeep Banerjee
Can a method Return More than one Value?
By Sandeep Banerjee in C# on Sep 16 2014
  • Anoop Kumar Sharma
    Sep, 2014 25

    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

    • 4
  • sushil kumar
    Feb, 2017 9

    Generally method return only one value but if we want method should return multiple values then it is possible. there are many option that make method to return multiple values. we can use tuple,ref,out....etc

    • 1
  • Joe Wilson
    Dec, 2015 11

    Yes

    • 1
  • vidya shrungare
    Aug, 2021 11

    Yes

    • 0
  • Riya updates
    Aug, 2021 4

    Yes

    • 0
  • Prasant Jaiswal
    Jul, 2021 30

    Yes

    • 0
  • spoorthi Pallakki pallakki
    Sep, 2020 25

    Yes

    • 0
  • jagadish pampana
    Feb, 2019 14

    No, but we can achieve with array

    • 0
  • Shailesh Maurya
    Feb, 2019 14

    yes

    • 0
  • Johan Sequeira
    Jan, 2019 29

    yes

    • 0
  • aamir ali
    May, 2018 4

    Yes

    • 0
  • Sanjay Maurya
    Nov, 2015 21

    yes

    • 0
  • Akash Varshney
    Oct, 2015 10

    yes.. we need ref and out to do this

    • 0
  • Ajeet Mishra
    Sep, 2015 3

    No

    • 0
  • Srinivas Pabballa
    Aug, 2015 28

    no way. a method will return only one value at a time.. if anybody says more than one value they are absolutely wrong... a method can't return more than one value at a time call by value call by reference and call by out are the parameter passing mechanisms that is not called returning a value.

    • 0
  • anusha raju
    Aug, 2015 18

    yes

    • 0
  • anusha raju
    Aug, 2015 18

    yes

    • 0
  • Sreeni Dony
    Jul, 2015 22

    Yes.By using out parameter

    • 0
  • Sourabh Somani
    Jul, 2015 20

    Yes! A method can return more that one value using out parameter in C#.

    • 0
  • Joe Wilson
    Jul, 2015 20

    yes it is possible but it is not usual.

    • 0
  • Rahul Prajapat
    Jun, 2015 1

    Sandeep Banerjee Can a method Return More than one Value? Posted by Sandeep Banerjee in C# Programming on Sep 16, 20142101422Do you know the answer for this question? Post it below. Rahul Anoop Kumar Sharma Posted by Anoop Kumar Sharma on Sep 25, 20143Usually 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, 20150No, Method Return Only one value Abrar Ahmad Ansari Posted by Abrar Ahmad Ansari on Mar 10, 20150Yes you can return more then one value--> use Tuple Concept.while using below code remove "" quotation from below method return typeclass 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, 20150Yes,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();}

    • 0
  • Kml Surani
    Apr, 2015 15

    No, Method Return Only one value

    • 0
  • Abrar Ahmad Ansari
    Mar, 2015 10

    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); } }

    • 0
  • Pankaj  Kumar Choudhary
    Feb, 2015 21

    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(); }

    • 0
  • Pramod Verma
    Jan, 2015 25

    No.

    • 0
  • Friyank Parikh
    Jan, 2015 6

    use OUT parameter for returning multiple values and if the return value are many , than return list of those value .

    • 0
  • Manish Kumar Choudhary
    Nov, 2014 18

    No. it's not possible theoretically. we can return multiple value by using collection.

    • 0
  • Dhanik Sahni
    Oct, 2014 9

    Yes. using yield, we can return multiple values in iteration. Please see http://stackoverflow.com/questions/1407162/what-is-yield-return-in-c .

    • 0
  • Munesh Sharma
    Oct, 2014 1

    yes http://www.dotnetperls.com/multiple-return-values

    • 0
  • Sandeep Banerjee
    Sep, 2014 16

    The answer is no a method is limited to returning just a single return value. However, it is possible to return an Array. An Array is a data structure that is actually a collection of Same variable.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS