I would like to skip the remainder of a function and call another should a statement prove true.

public bool A(int i)
        {
            if (i > 5)
            {
                // Skip the rest of A() and return B()
                return B(i);
            }

            // Do stuff to i
        }

        public bool B(int i)
        {
            // Do stuff to i
        }

Is my only option to have the return value as a bool, even if I don't care what the boolean return value is?

This is for when not wanting it to return anything. Notice that when returning nothing, it will just exit out of the method.

public void A(int i)
        {
            if (i > 5)
            {
                // Skip the rest of A() and return B()
                B(i);
                return;
            }

            // Do stuff to i
        }

        public void B(int i)
        {
            // Do stuff to i
        }

Thank you. :)

Does this have any speed advtanges over returning bool?

Edited 6 Years Ago by DaveTran: n/a

Not really. You only want to use bool or anything returned if you will be doing logic on it later.

This question has already been answered. Start a new discussion instead.