I'm wondering if this is possible to do in c#.
Let's say i have a class with these methods:
public class Ladder
{
private int currentStep = 0;
Ladder Up()
{
currentStep++;
return this;
}
Ladder Down()
{
currentStep--;
return this;
}
}
I can use it like this:
Ladder ladder = new Ladder();
ladder.Up().Up().Up().Down().Down();
Now, I would like to add a conditional method, that could be used like this:
ladder.IF(somecondition, Up(), Down());
Meaning if somecondition == true then execute Up(), else Down()
Is it possible to do? I was thinking about using anonymous methods, but can't figure out how to reference "this" instance so it would know what that these functions are referred to.
Any help is greatly appreciated!