我有一個名爲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