À titre d'exemple:Lors de l'utilisation d'un délégué, existe-t-il un moyen d'obtenir la réponse de l'objet?
Code normal:
private void wcDownloadStringCompleted(
object sender, DownloadStringCompletedEventArgs e)
{
// The result is in e.Result
string fileContent = (string)e.Result;
}
public void GetFile(string fileUrl)
{
using (WebClient wc = new WebClient())
{
wc.DownloadStringCompleted +=
new DownloadStringCompletedEventHandler(wcDownloadStringCompleted);
wc.DownloadStringAsync(new Uri(fileUrl));
}
}
Mais si nous utilisons un delegate
anonyme comme:
public void GetFile(string fileUrl)
{
using (WebClient wc = new WebClient())
{
wc.DownloadStringCompleted +=
delegate {
// How do I get the hold of e.Result here?
};
wc.DownloadStringAsync(new Uri(fileUrl));
}
}
Comment puis-je obtenir la prise de e.Result
là?