jeudi 20 mai 2021

Refactor if statement in C#

Is there a better way to write this if statement in C#?

if (a.Exists)
{
  if (b.Exists)
  {
    logic
  }
  else
  {
    morelogic
  }
}
else
{
  logic
}

Where "logic" is the same copied logic? I would like to have "logic" and "morelogic" appear only once in the statement.

Aucun commentaire:

Enregistrer un commentaire