C# replacing out parameters with struct

Posted by Jonathan on Programmers See other posts from Programmers or by Jonathan
Published on 2012-09-25T08:26:21Z Indexed on 2012/09/25 9:48 UTC
Read the original article Hit count: 275

Filed under:
|

I'm encountering a lot of methods in my project that have a bunch of out parameters embedded in them and its making it cumbersome to call the methods as I have to start declaring the variables before calling the methods.

As such, I would like to refactor the code to return a struct instead and was wondering if this is a good idea.

One of the examples from an interface:

void CalculateFinancialReturnTotals(FinancialReturn fr, out decimal expenses, out decimal revenue, out decimal levyA, out decimal levyB, out decimal profit, out decimal turnover, out string message)

and if I was to refactor that, i would be putting all the out parameters in the struct such that the method signature is much simpler as below.

[structName] CalculateFinancialReturnTotals(FinancialReturn fr);

Please advise.

© Programmers or respective owner

Related posts about c#

Related posts about refactoring