我WebClient
用来下载图像的代码非常大,所以我试图将我的代码分成类。有人可以给我一个示例,说明如何将下面的代码放入类或函数中吗?
WebClient client = new WebClient ();
client.DownloadDataCompleted +=
(object sender, DownloadDataCompletedEventArgs e) =>
{
byte[] result = e.Result;
if (result != null)
{
NSData data1 = NSData.FromArray (e.Result);
UIImage img = UIImage.LoadFromData (data1);
InvokeOnMainThread (delegate {
avatar.Image = img;
});
}
};
client.DownloadDataAsync(new Uri(
"http://xx.xx.xx.xx/fbcache/" +
list[indexPath.Row].comentario_id_usuario +
".jpg"));