我有一个名为FrameList的自定义对象(PONO)的数组,我可以orderBy和GroupBy进行排序和分组。但现在我想回到一个字典,而我得到的错误:(顺便说一句,有没有错误是我删除了.ToDictionary()方法)Linq排序,分组和返回字典
Error 1 'System.Linq.IGrouping' does not contain a definition for 'type' and no extension method 'type' accepting a first argument of type 'System.Linq.IGrouping' could be found (are you missing a using directive or an assembly reference?) C:\Users\ysg4206\Documents\Visual Studio 2010\Projects\Watson\CatalogServiceClasses\BuildToby.cs 21 38 Watson
这里是代码段中排序和组:
var dict = request.FrameList.OrderBy(f => f.trueDate)
.GroupBy(f => f.type)
.ToDictionary(f => f.type, f => f);
和这里是页框的定义(这是FrameData的一个简单的数组)
[DataContract]
public class FrameData
{
[DataMember]
public String idx { get; set; }
[DataMember]
public String type { get; set; }
[DataMember]
public String path { get; set; }
[DataMember]
public String date { get; set; }
[DataMember]
public DateTime trueDate { get; set; }
}
'.ToDictionary(F => f.Key,F => F)'的IGrouping将组中的元素按类型分为关键。 – Romoku 2013-03-18 16:35:31