【发布时间】:2012-01-20 22:06:26
【问题描述】:
我收到了一个我从以下代码中不太明白的错误:
public IList<Store> getNearbyStores(double x, double y)
{
var result = (from T in
(
(from stores in dc.Stores
select new
{
stores.id,
stores.name,
stores.city,
stores.typeID,
stores.latitude,
stores.longitude,
stores.tag1,
stores.tag2,
Distance = (System.Double?)(6371 * Math.Acos((double)Math.Cos((double)(Math.PI * x) / 180) * Math.Cos((double)(Math.PI * stores.latitude) / 180) * Math.Cos((double)(Math.PI * stores.longitude) / 180 - (Math.PI * y) / 180) + Math.Sin((double)(Math.PI * x) / 180) * Math.Sin((double)(Math.PI * stores.latitude) / 180)))
}))
where
T.Distance < 5
orderby
T.Distance
select new
{
T.id,
T.name,
T.city,
T.typeID,
T.latitude,
T.longitude,
T.tag1,
T.tag2,
T.Distance
}).ToList();
return result;
}
错误是:
Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.IList<Store>'. An explicit conversion exists (are you missing a cast?) C:\Users\Joris\Desktop\ShopperNET\App_Code\DAL\DALstore.cs 104 16 C:\...\ShopperNET\
如何将匿名返回类型转换为 IList?我认为 toList() 会修复它,但它没有..我尝试了一些我在网上找到的东西,比如只使用“列表”,但没有一个真正帮助我。
提前致谢。
【问题讨论】:
标签: c# asp.net .net casting ilist