vendredi 18 avril 2014

c# - appel d'une méthode d'une autre classe sans relation - Stack Overflow


I'm learning to code, but there are things that i still don't know. As it is difficult to me explain what I want, here I show the code.


public class classOne {

classTwo object = new ClassTwo();

(...)

public void WhenClassTwoHasEnded {
(...)
}
}

public class classTwo {

public classTwo () {(...)}

public classTwoAsyncStuff {
(...)
notifyEnd();
}

public void notifyEnd() {
//How I can call WhenClassTwoHasEnded from here?
}
}

Usually I always find the answer to my questions on Stack Overflow, but I've been searching for a while and have not found anything, because of my English.




It's possible to do that in many different ways. Here are some:



1) Let ClassOne run the method of its ClassTwo instead of calling it directly. So ClassOne has an (async if you want) method in which it calls await classTwo.classTwoAsyncStuff() and then this.WhenClassTwoHasEnded()


2) You could add event handlers


3) You could also send the Action or Func to the method and let it run it when it's done.




I'm learning to code, but there are things that i still don't know. As it is difficult to me explain what I want, here I show the code.


public class classOne {

classTwo object = new ClassTwo();

(...)

public void WhenClassTwoHasEnded {
(...)
}
}

public class classTwo {

public classTwo () {(...)}

public classTwoAsyncStuff {
(...)
notifyEnd();
}

public void notifyEnd() {
//How I can call WhenClassTwoHasEnded from here?
}
}

Usually I always find the answer to my questions on Stack Overflow, but I've been searching for a while and have not found anything, because of my English.



It's possible to do that in many different ways. Here are some:



1) Let ClassOne run the method of its ClassTwo instead of calling it directly. So ClassOne has an (async if you want) method in which it calls await classTwo.classTwoAsyncStuff() and then this.WhenClassTwoHasEnded()


2) You could add event handlers


3) You could also send the Action or Func to the method and let it run it when it's done.



0 commentaires:

Enregistrer un commentaire