calling methods if previous call success

Posted by New Developer on Programmers See other posts from Programmers or by New Developer
Published on 2014-06-08T12:50:33Z Indexed on 2014/06/08 15:42 UTC
Read the original article Hit count: 199

Filed under:

I my c# program I have to perform 5 steps(tasks) sequentially. basically these five should execute one after the other only the previous task performed is success. Currently I have done it in following style. But this is not very good code style to follow.

var isSuccess=false;
isSuccess=a.method1();

if(isSuccess)
    isSuccess=a.method2();

if(isSuccess)
    isSuccess=a.method3();

if(isSuccess)
    isSuccess=a.method4();

if(isSuccess)
    isSuccess=a.method5();

How can I re factor this code. What is the best way I can follow?

© Programmers or respective owner

Related posts about c#