C# – How to cancel the execution of a method

c++

Consider i execute a method 'Method1' in C#.
Once the execution goes into the method i check few condition and if any of them is false, then the execution of Method1 should be stopped. how can i do this, i.e can the execution of a method when certain conditions are met.?

but my code is something like this,

int Method1()
{
    switch(exp)
    {
        case 1:
        if(condition)
            //do the following. **
        else
            //Stop executing the method.**
        break;
        case2:
        ...
    }
}

Best Solution

Use the return statement.

if(!condition1) return;
if(!condition2) return;

// body...