我正在编写C#Xamarin应用程序,并收到以下错误:
Error CS0029: Cannot implicitly convert type 'System.Collections.Generic.List<SimpleMapDemo.AndroidMapLocationImageViewModel>' to 'System.Collections.Generic.List<SimpleMapDemo.AndroidIGridViewItemWithAssets>'
我在这一行收到错误:
return androidMapLocationImageGalleryViewModel.images;
在以下功能中:
public List<AndroidIGridViewItemWithAssets> GetAndroidMapLocationItemGridViewItemsFromWebService(string type, int webServiceId)
{
if (type.Equals("Image Gallery"))
{
AndroidMapLocationImageGalleryViewModel androidMapLocationImageGalleryViewModel = GetAndroidMapLocationImageGallery (webServiceId);
return androidMapLocationImageGalleryViewModel.images;
}
return null;
}
这是我的AndroidMapLocationImageGalleryViewModel
代码:
public class AndroidMapLocationImageGalleryViewModel
{
public int mapLocationItemImageGalleryId { get; set; } //may not be needed
public List<AndroidMapLocationImageViewModel> images;
public AndroidMapLocationImageGalleryViewModel ()
{
images = new List<AndroidMapLocationImageViewModel> ();
}
}
AndroidMapLocationImageViewModel
继承自AndroidIGridViewItemWithAssets
。
我可以帮助您使用此代码吗?
提前致谢
答案 0 :(得分:1)
你需要:
return androidMapLocationImageGalleryViewModel.images
.Cast<AndroidIGridViewItemWithAssets>()
.ToList();
施法方法:http://msdn.microsoft.com/en-us/library/bb341406(v=vs.110).aspx