0

I have a few methods that have similar structure to each other. The only difference is the variable that is begin tested and which boolean condition is required.

public void OP_BCS(sbyte b)
{
    cv.PC += 2;

    if (cv._C == true)
    {
        cv.PC += (ushort)b;
    }
}

Is it possible to change the above code to something similar to what I have below (syntax might be incorrect, but should work in explaining what I mean)

public void OP_Branch(variable name, boolean condition, sbyte b)
{
    cv.PC += 2;

    if (variable == condition)
    {
        cv.PC += (ushort)b;
    }
}

I'd be able to make all the different combinations I need simply by giving the method a few extra parameters.

BG1SC
  • 101
  • 6

1 Answers1

0

Why not just take a bool as a parameter?

public void OP_Branch(bool condition, sbyte b)
{
    cv.PC += 2;

    if (condition)
    {
        cv.PC += (ushort)b;
    }
}

Then when you call it, you do the comparison in the method call:

OP_Branch(variable == condition, b);
Gabriel Luci
  • 38,328
  • 4
  • 55
  • 84