Support conversion to Boolean but still have WriteLine display using ToString
<p>When I run this bit of code, <code>Equation(10, 20)</code> is output to the console:</p>

<pre><code>public class Equation
{
    public int a;
    public int b;

    public override string ToString()
    { return "Equation(" + a + ", " + b + ")"; }
}

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(new Equation() { a = 10, b = 20 });

        Console.ReadLine();
    }
}
</code></pre>

<p>I'd like to support <code>Equation</code> instances being used in the test of an <code>if</code> so I allowed for implicit conversion to <code>Boolean</code>:</p>

<pre><code>public class Equation
{
    public int a;
    public int b;

    public override string ToString()
    { return "Equation(" + a + ", " + b + ")"; }

    public static implicit operator Boolean(Equation eq)
    { return eq.a == eq.b; }
}

class Program
{
    static void Main(string[] args)
    {
        if (new Equation() { a = 10, b = 10 })
            Console.WriteLine("equal");

        Console.WriteLine(new Equation() { a = 10, b = 20 });

        Console.ReadLine();
    }
}
</code></pre>

<p>However, the trouble is, now when I use <code>WriteLine</code> on an <code>Equation</code>, it get's converted to a <code>Boolean</code> instead of printing using <code>ToString</code>.</p>

<p>How can I allow for implicit conversion to <code>Boolean</code> and still have <code>WriteLine</code> display using <code>ToString</code>?</p>

<hr>

<p><strong>update</strong></p>

<p>This question is inspired by the <code>Equation</code> class in <a href="http://issc.uj.ac.za/symbolic/symbolic.html" rel="nofollow">SymbolicC++</a>. The code below illustrates that an <code>Equation</code> can be displayed via <code>cout</code> as well as used in the test of an <code>if</code>:</p>

<pre><code>auto eq = x == y;

cout &lt;&lt; eq &lt;&lt; endl;

if (eq)
    cout &lt;&lt; "equal" &lt;&lt; endl;
else
    cout &lt;&lt; "not equal" &lt;&lt; endl;
</code></pre>

<p>So this is somehow possible in C++.</p>
