Simplyfing code with a lot of ifs

Posted by user278618 on Stack Overflow See other posts from Stack Overflow or by user278618
Published on 2011-01-02T17:19:02Z Indexed on 2011/01/02 17:54 UTC
Read the original article Hit count: 188

Filed under:
|
|

I have a method which based on the enum, and to be clear at start we have this situation:

public void MyMetohd(Somestatus status)
{
if(status == Somestatus.Enum1)
{
DoA();
DoB();
DoC();
DoD();
DoE();
}
if(status == Somestatus.Enum2)
{
DoA();
DoB();
DoC();
DoD();
}

if(status == Somestatus.Enum3)
{
DoA();
DoB();
DoC();
}

if(status == Somestatus.Enum4)
{
DoA();
DoB();
}

if(status == Somestatus.Enum5)
{
DoA();
}
}

How would you optimize this kind of code ( it isn't mine)?

© Stack Overflow or respective owner

Related posts about c#

Related posts about optimization