Aniket Narvankar

Aniket Narvankar

  • 527
  • 2.1k
  • 579.8k

C Sharp If Statements

Sep 14 2021 8:53 AM

In my application there are 5 methods,in all methods there are update queries. Methods are depedent on each other. If first method runs successfully,second is called,second runs successfully third is called,third runs successfully fourth is called,fourth runs successfully fifth is called.

here is code

public void method1()

{

      int result = cmd.ExecuteNonQuery();

if(result > 0)

{

     method2();

}

}

public void method2()

{

      int result = cmd.ExecuteNonQuery();

if(result > 0)

{

     method3();

}

}

public void method3()

{

      int result = cmd.ExecuteNonQuery();

if(result > 0)

{

     method4();

}

}

public void method4()

{

      int result = cmd.ExecuteNonQuery();

if(result > 0)

{

     method5();

}

}

I want to write this same code without using if statement,switch case or ternary operators. please guide me on how to do this.