I have a class in java which basically performs a search in asynchronous and me returns the result through a listener, I need to write this same routine in C # I know there are some differences between java and therefore unable to write, I am beginner in c # I need at least a horizon.
public class Operation {
private List<Operation.Listener> ListEventResult = new ArrayList<Operation.Listener>();
public void Search(String word){
try {
Thread.sleep(3000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
if(ListEventResult.size()>0){
for(Operation.Listener li : ListEventResult){
li.Result("Result for "+word);
}
}
}
public void addEventResult(Listener li){
ListEventResult.add(li);
}
public interface Listener{
public void Result(String result);
}
}
public class Program {
public static void main(String[] args) {
// TODO Auto-generated method stub
Operation op = new Operation();
op.addEventResult(new Operation.Listener() {
@Override
public void Result(String result) {
System.out.println(result);
}
});
op.Search("Facebook");
}
}