Multiple if then return with conditions Is there a more elegant way of doing this? I really think this looks ugly.

private static string InsertMethodNameHere( bool hasCondition1, bool hasCondition, bool hasCondition3)
        {    
            if (!hasCondition1 &amp;&amp; !hasCondition2 &amp;&amp; !hasCondition3)
                return "0";

            if (hasCondition1 &amp;&amp; !hasCondition2 &amp;&amp; !hasCondition3)
                return "1";

            if (!hasCondition1 &amp;&amp; hasCondition2 &amp;&amp; !hasCondition3)
                return "2";

            if (hasCondition1 &amp;&amp; hasCondition2 &amp;&amp; !hasCondition3)
                return "3";

            if (!hasCondition1 &amp;&amp; !hasCondition2 &amp;&amp; hasCondition3)
                return "4";

            if (hasCondition1 &amp;&amp; !hasCondition2 &amp;&amp; hasCondition3)
                return "5";

            if (!hasCondition1 &amp;&amp; hasCondition2 &amp;&amp; hasCondition3)
                return "6";

            if (hasCondition1 &amp;&amp; hasCondition2 &amp;&amp; hasCondition3)
                return "7";

            throw new Exception("Unable to determine.");
}
How about this?

private static string InsertMethodNameHere(bool hasCondition1, bool hasCondition2, bool hasCondition3)
{
    return ((hasCondition1 ? 1 : 0) +
            (hasCondition2 ? 2 : 0) +
            (hasCondition3 ? 4 : 0)).ToString(CultureInfo.InvariantCulture);
}


If you want a more general solution, you could write an extension method that converts a list of bools to an int:

public static int ToInt(this IEnumerable&lt;bool&gt; bools)
{
    return bools.Select((t, i) =&gt; (t ? 1 : 0) &lt;&lt; i).Sum();
}