Is it possible for a function to return two values?
Array is possible if the two values are both the same type, but how do you return two different type values?
Is it possible for a function to return two values? Array is possible if
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Can a function return 2 separate values? No, a function in C# can only return a single value.
It is possible though to use other concepts to return 2 values. The first that comes to mind is using a wrapping type such as a
Tuple<T1,T2>.The
Tuple<T1,T2>type is only available in 4.0 and higher. If you are using an earlier version of the framework you can either create your own type or useKeyValuePair<TKey,TValue>.Another method is to use an out parameter (I would highly recomend the tuple approach though).