I am new to C # and I am trying to find a better way to check if the method will return correctly, i.e. this method got the information I wanted.
These are the types that make it difficult. Is there a way that I can sometimes return a bool and sometimes return something else?
In PHP, I would create my own function like this
function myFunc(){ //Do Stuff if(/*whatever*/) return (string) "abcdefg"; return false; //otherwise it will just return false }
Then call it up to check if it works or not.
if(!$var=myFunc()) die("It Didn't Work"); echo $var;
But with C #, my function should return the specified type, not a string, or bool false if that didn't work.
If in C # I have a method that returns IntPtr, I could return it (IntPtr) 0 instead of false, but this is dirty and probably the best way to do this.
Any ideas? What is the standard and usual way to do this in C #?
source share