简体   繁体   English

在c#中向EventHandler添加一些参数

[英]Add some parameter to EventHandler in c#

By now I'm having this code 到现在为止我有这个代码

public void getRankingList(string country,string type)
    {            
        WebClient client = new WebClient();
        client.AllowReadStreamBuffering = true;
        string url = "......";
        client.DownloadStringCompleted += getRankingResult;
        client.DownloadStringAsync(new Uri(url, UriKind.Absolute));
    }
private void getRankingResult(object sender, DownloadStringCompletedEventArgs e)
    {
        .........
    }

So now can I add some para to the downloadCompleted event ? 那么我现在可以在downloadCompleted事件中添加一些para吗? something like: 就像是:

private void getRankingResult(object sender, DownloadStringCompletedEventArgs e, string Para)
    {
        .........
    }
public void getRankingList(string country,string type)
    {            
        WebClient client = new WebClient();
        client.AllowReadStreamBuffering = true;
        string url = "......";
        client.DownloadStringCompleted += (sender, args) => 
        getRankingResult(sender, args, "para");
        client.DownloadStringAsync(new Uri(url, UriKind.Absolute));
    }

private void getRankingResult(object sender, DownloadStringCompletedEventArgs e, string Para)
{
    // .....
}

如果DownloadStringCompletedEventArgs不是密封类,那么您可以创建一个新类并从中继承并向其添加附加string Para字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM