Are ‘out’ parameters a bad thing in .NET? Any good articles/discussions on this topic?
Are out parameters a bad thing in .NET? Any good articles/discussions on this topic?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, I have an article on what ref/out do – but it doesn’t discuss whether or not you should use them.
Basically
outparameters are usually a sign that you want to effectively return two results from a method. That’s usually a code smell – but there are some cases (most notably with the TryXXX pattern) where you genuinely want to return two pieces of information for good reasons and it doesn’t make much sense to encapsulate them together.In other words, avoid out/ref where you can do so easily, but don’t go massively out of your way to avoid them.