Is it possible for a function to return two values?

后端 未结 13 1571
谎友^
谎友^ 2020-12-31 08:41

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?

13条回答
  •  我在风中等你
    2020-12-31 09:24

    You have basically (at least) two options, either you make an out parameter in addition to the return value of the function, something like T1 Function(out T2 second) or you make your own class putting these two types together, something like a Pair. I personally prefer the second way but it's your choice.

提交回复
热议问题