Returning two values, Tuple vs 'out' vs 'struct'

前端 未结 6 1178
傲寒
傲寒 2020-12-24 04:23

Consider a function which returns two values. We can write:

// Using out:
string MyFunction(string input, out int count)

// Using Tuple class:
Tuple

        
6条回答
  •  情话喂你
    2020-12-24 04:51

    I will go with the approach of using Out parameter because in second approach you would require to create and object of Tuple class and then add value to it, which I think is an costly operation compared to returning the value in out parameter. Though if you want to return multiple values in Tuple Class (which infact can not be accomplished by just returning one out parameter) then I will go for second approach.

提交回复
热议问题