I am asking is the C # method return multiple values | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

I am asking is the C # method return multiple values

C# method multiple retun values

9th Feb 2018, 4:30 PM
mohamed saeed
4 Answers
+ 5
Like sneeze already wrote, methods can only have 1 return value (or void), but you could pass arguments by reference. Another nice way supported in C# is passing by output. Check the "Passing Arguments" lesson (Methods 5/8) in the C# course for more information.
9th Feb 2018, 6:44 PM
Chris
Chris - avatar
+ 1
In general a method can only return one value (int, bool, string). However there a few ways to return multiple values. You can make the return type a list having the values in the list. Or use ref parameters.
9th Feb 2018, 4:51 PM
sneeze
sneeze - avatar
+ 1
I wrote some code to show that it is possible to return multiple values with one method. https://code.sololearn.com/cX41bh0Svo48 Please put the language you use in your tags
9th Feb 2018, 10:08 PM
sneeze
sneeze - avatar
0
thanks a lot sneeze and Chris I saw you code
10th Feb 2018, 3:31 PM
mohamed saeed