How do I output multiple values from a method, and still follow proper design principles?

.net, c#

Solution

I would rank your options this way:

- create a class that would hold each output value I want and my method will return that

- return value along with multiple out/ref parameters

- construct an XML string that contains all the output values I want

However, all of these represent a "code smell" that your method is doing too much. At least returning a class indicates that the method is providing several known, related values. Using `out`/`ref` is more of a workaround (sometimes they're valid, sometimes they're not) to avoid creating a class, and XML is not a good choice since you force the consumer to know the schema in order to extract the values.

Problem

Say I have a method that requires more that two output values. My options would be the following (maybe there are more options I haven't considered) - return value along with multiple out/ref parameters - create a class that would hold each output value I want and my method will return that - construct an XML string that contains all the output values I want and return that I'm asking because i remember reading somewhere that it not good to use out and ref parameters. But I'm not sure how else to do it. Which way adheres best to design principles and also makes it better for unit testing? Also are there other options I didn't list that would be acceptable? EDIT: the extra output values I'm considering to return in addition to the main value, have to do with success failure condition of the process as well as the name of the condition that failed etc. So mostly for tracking and testing of the process.

Original source