[英]Cannot implicitly convert type
I have the following function 我有以下功能
public Dictionary<DateTime, object> GetAttributeList(
EnumFactorType attributeType,
Thomson.Financial.Vestek.Util.DateRange dateRange)
{
DateTime startDate = dateRange.StartDate;
DateTime endDate = dateRange.EndDate;
return (
//Step 1: Iterate over the attribute list and filter the records by
// the supplied attribute type
from assetAttribute in AttributeCollection
where assetAttribute.AttributeType.Equals(attributeType)
//Step2:Assign the TimeSeriesData collection into a temporary variable
let timeSeriesList = assetAttribute.TimeSeriesData
//Step 3: Iterate over the TimeSeriesData list and filter the records by
// the supplied date
from timeSeries in timeSeriesList.ToList()
where timeSeries.Key >= startDate && timeSeries.Key <= endDate
//Finally build the needed collection
select timeSeries);
}
Error:Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<System.Collections.Generic.Dictionary<System.DateTime,object>>'
to 'System.Collections.Generic.Dictionary<System.DateTime,object>'.
An explicit conversion exists (are you missing a cast?)
Using C# 3.0 使用C#3.0
It's difficult to know what you really want without more information on your structures. 如果没有更多有关结构的信息,很难知道您真正想要什么。 What should the return object be - the asset attribute or the time series?
返回对象应该是什么-资产属性或时间序列? If it's the attribute then something like this should work
如果它是属性,那么类似的东西应该起作用
//Finally build the needed collection
select new {timeSeries.Key, assetAttribute})
.ToDictionary(t => t.Key, t => (object)t.assetAttribute);
or if it's just the time series then 或者如果只是时间序列
//Finally build the needed collection
select timeSeries).ToDictionary(t => t.Key, t => (object)t);
I'm not a LINQ guru so there may be better ways to do this but these ought to compile at least. 我不是LINQ专家,所以也许有更好的方法可以做到这一点,但是至少应该编译一下。
[edit] just spotted your function name: I guess you want the first one then. [edit]刚发现您的函数名称:我想您想要第一个。
the return type of 的返回类型
return ((
//Step 1: Iterate over the attribute list and filter the records by
// the supplied attribute type
from assetAttribute in AttributeCollection
where assetAttribute.AttributeType.Equals(attributeType)
//Step2:Assign the TimeSeriesData collection into a temporary variable
let timeSeriesList = assetAttribute.TimeSeriesData
//Step 3: Iterate over the TimeSeriesData list and filter the records by
// the supplied date
from timeSeries in timeSeriesList.ToList()
where timeSeries.Key >= startDate && timeSeries.Key <= endDate
//Finally build the needed collection
select new AssetAttribute()
{
AttributeType = assetAttribute.AttributeType
,
Periodicity = assetAttribute.Periodicity
,
TimeSeriesData = PopulateTimeSeriesData(timeSeries.Key, timeSeries.Value)
}).ToList<AssetAttribute>().Select(i => i.TimeSeriesData));
is IEnumerable but the function should return Dictionary 是IEnumerable,但函数应返回Dictionary
public Dictionary<DateTime, object> GetAttributeList(
EnumFactorType attributeType
,Thomson.Financial.Vestek.Util.DateRange dateRange)
{
DateTime startDate = dateRange.StartDate;
DateTime endDate = dateRange.EndDate;
return (
//Step 1: Iterate over the attribute list and filter the records by
// the supplied attribute type
from assetAttribute in AttributeCollection
where assetAttribute.AttributeType.Equals(attributeType)
//Step2:Assign the TimeSeriesData collection into a temporary variable
let timeSeriesList = assetAttribute.TimeSeriesData
//Step 3: Iterate over the TimeSeriesData list and filter the records by
// the supplied date
from timeSeries in timeSeriesList.ToList()
where timeSeries.Key >= startDate && timeSeries.Key <= endDate
select new { timeSeries.Key, timeSeries.Value })
.ToDictionary(x => x.Key, x => x.Value);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.