Is it possible for a function to return two values?

后端 未结 13 1535
谎友^
谎友^ 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:38

    It is not directly possible. You need to return a single parameter that wraps the two parameters, or use out parameters:

    object Method(out object secondResult)
    {
        //...
    

    Or:

    KeyValuePair Method()
    {
       // ..
    

提交回复
热议问题