No, you are essentially asking the function to exit the function above itself, which is undesirable or really impossible if you do not throw an exception (which does not return by itself).
That way, you can either do your simple and succinct if-null-return checks, or what you might want to do there is to throw a well-defined exception, but I do not recommend exceptions for flow control. However, if these are exceptional (error) circumstances, then consider throwing ArgumentNullException () and handling it accordingly.
You could write some helper methods to throw ArgumentNullException () for you, of course, clean it up a bit:
public static class ArgumentHelper { public static void VerifyNotNull(object theObject) { if (theObject == null) { throw new ArgumentNullException(); } } public static void VerifyNotNull(params object[] theObjects) { if (theObjects.Any(o => o == null)) { throw new ArgumentNullException(); } } }
Then you could write:
public void SomeMethod(object obj1, object obj2, object obj3) { ArgumentHelper.VerifyNotNull(obj1, obj2, obj3);
But again, these are exceptions, not the βreturnβ of the previous method on the stack, which is impossible.
source share