when to use ref and out in c#
when to use ref and out in c#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
KalaiPosted May 16, 2014, 9:26 AM
VulpesPosted May 16, 2014, 8:15 AM
This is what ref and out parameters do.
The difference between them is that out parameters do not need to be initialized before being passed to the method but you are guaranteed that they will be assigned a value before the method returns. They are therefore useful when you want to return more than one value from a method.
In contrast ref parameters do need to be initialized before being passed to the method and may or may not be assigned a different value within the method itself.