Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the pros and cons of using out parameter

Tags:

c#

.net

Anyone can point out the pros and cons of the out parameter. When it is preferred to use out parameter rather than just to return a value.

like image 868
user496949 Avatar asked Dec 28 '22 05:12

user496949


1 Answers

Out parameters effectively allow you to return multiple values from a method, and this is generally preferable to returning an arbitrary struct or tuple which contains multiple values.

One might argue that it's easier to overlook the possible side effects of a function which uses an out parameter, as it departs from the traditional 'multiple parameters, one return value' model. But I honestly think that the out keyword coupled with a method post-condition makes the programmer's intention quite clear.

like image 192
asdfjklqwer Avatar answered Jan 13 '23 16:01

asdfjklqwer