我有一个比较功能,其中有3个要比较的项目。
我的问题是如何获取带有其相应的ID
的属性。
[System.Web.Http.HttpGet]
public List<Compares> CompareValues(string ids)
{
var result = new List<Compares>();
if (!string.IsNullOrEmpty(ids))
{
var nodes = ids.Split(',').ToList().TypedContentList();
return nodes.Select(x => new KeyValuePair<int, string>(x.Id, x.GetPropertyValue<string>("title"))).ToList();
/// Error : Cannot implicity convert type 'System.Collections.Generic.List....
}
return result;
}
完整的消息如下:
无法将类型'System.Collections.Generic.IEnumerable'隐式转换为'System.Collections.Generic.List'。存在显式转换(您是否缺少演员表?)
感谢任何帮助。
谢谢。
Jin
答案 0 :(得分:0)
您的函数希望返回一个List<Compares>
。
此行:
return nodes.Select(x => new KeyValuePair<int, string>(x.Id, x.GetPropertyValue<string>("title"))).ToList();
不返回List<Compares>
,而是返回KeyValuePairs<int,string>
的列表。