What is the best way to implement a method with 2 returns?
<p>Quite often I come across some code where I have to return a boolean to indicate whether the method finished successfully or not and a string with an error message in case of a problem.</p>

<p>I've implemented this in two ways.
The first consists in a class of response and all methods of all classes use this response class to communicate. Example:</p>

<pre><code>public class ReturnValue {
    public bool Ok;
    public string Msg;
    public object SomeData;

    public ReturnValue() {
        this.Ok = true;
        this.Msg = null;
    }

    public ReturnValue(string Msg) {
        this.Ok = true;
        this.Msg = Msg;
    }

    public ReturnValue(object SomeData) {
        this.Ok = true;
        this.SomeData = SomeData;
    }

    public ReturnValue(bool Ok, string Msg) {
        this.Ok = Ok;
        this.Msg = Msg;
    }

    public ReturnValue(bool Ok, string Msg, object SomeData) {
        this.Ok = Ok;
        this.Msg = Msg;
        this.SomeData = SomeData;
    }
}

public class Test {
    public ReturnValue DoSomething() {
        if (true) {
            return new ReturnValue();
        } else {
            return new ReturnValue(false, "Something went wrong.");
        }
    }
}
</code></pre>

<p>The second way is to have a method that stores the message in case of error and to see the message simply call this method. Example:</p>

<pre><code>public class Test {
    public string ReturnValue { get; protected set; }

    public bool DoSomething() {
        ReturnValue = "";

        if (true) {
            return true;
        } else {
            ReturnValue = "Something went wrong.";
            return false;
        }
    }
}
</code></pre>

<p>There is a right way to do this?</p>
