How to cancel the execution of a method?

后端 未结 5 778
眼角桃花
眼角桃花 2020-12-30 08:18

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 shou

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-30 08:58

    Are you talking about multi threading?

    or something like

    int method1(int inputvalue)
    {
       /* checking conditions */
       if(inputvalue < 20)
       {
          //This moves the execution back to the calling function
          return 0; 
       }
       if(inputvalue > 100)
       {
          //This 'throws' an error, which could stop execution in the calling function.
          throw new ArgumentOutOfRangeException(); 
       }
       //otherwise, continue executing in method1
    
       /* ... do stuff ... */
    
       return returnValue;
    }
    

提交回复
热议问题