I am making a porting of this code from java(Android) to C#(Windows Phone) but i have no idea how to do that, here is the code that i'm trying do convert:
private void executeSingleOperation() {
operation.execute(new OperationResult() {
@Override
public void onSuccess(Object obj) {
//do something
this.executeSingleOperation();
}
@Override
public void onFail(Error err) {
//andle the error
}
});
}
OperationResult is an interface and looks like this:
public interface OperationResult {
public void onSuccess(Object obj);
public void onFail(Error err); }
Thanks in advance
There's no equivalent to anonymous inner classes in C#. For single-method versions, you can often use delegates instead of interfaces, then use lambda expressions (or just regular methods) to specify an implementation.
Otherwise, just use a regular class to implement the interface.
In this case, you might want to mix the two, having an implementation of the interface which itself takes two delegates in the constructor - one for failure and one for success. It really depends on the context, and we don't have a lot of that at the moment.
I would say that if you're fairly new to C#, you'd be better off investigating it in the context of a console app as a much simpler environment for experimentation.
See more on this question at Stackoverflow