method return types
<p>I'm new to C# and I'm trying to figure out the best way to test if a method returns correctly, ie; did the method get the information I wanted.</p>

<p>It's the types that are making this difficult. Is there a way that I can sometimes return bool and sometimes return something else?</p>

<p>In PHP I would create my function like this</p>

<pre><code>function myFunc(){
    //Do Stuff
    if(/*whatever*/) return (string) "abcdefg";
    return false; //otherwise it will just return false
}
</code></pre>

<p>Then call it like this to test if it worked or not</p>

<pre><code>if(!$var=myFunc()) die("It Didn't Work");
echo $var;
</code></pre>

<p>But with C#, my function has to return a specified type, not a string or bool false if it didn't work out.</p>

<p>If in C# I have a method that returns IntPtr I could have it return <code>(IntPtr) 0</code> instead of false, but this is messy and there's probably a better way of doing it. </p>

<p>Any Ideas? What's the standard and usual way of doing this in C#?</p>
