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?
&&
might be a good choice. Otherwise, you're just using return codes and should probably rethink the structure of your code, because this is a very procedural way to go about it. – Magus Jun 10 '14 at 16:18