以下link建議使用此語法:SortedList錯誤:「不包含Select的定義。」
var result = SortedList.Select(x => new {
x.Value.MyProperty,
x.Value.AnotherProperty
});
然而,當我嘗試測試它,我收到錯誤:
System.Collections.SortedList
does not contain a definition forSelect
.
我已經有以下引用:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using System.IO;
儘管廣泛的互聯網搜索,我無法弄清楚如何解決這個問題。誰能幫忙?
編輯: 也許我正在談論這個錯誤。我的目標是將SortedList的子集作爲SortedList返回。
var subset = data.Where(x => x.Key >= startDate && x.Key <= endDate);
其中 '數據' 是
SortedList<DateTime, BarData>
'barData' 是一類
請確保您有System.Core.dll除此之外,「排序列表」需要有一個實例變量 - 您使用的不知道,因爲「排序列表」是你的榜樣帕斯卡情況。 –
您是否嘗試過使用System.Collections.Generic.SortedList? – snurre
我得到了一個自定義詞典的「不包含Select的定義」的錯誤。我從來沒有找到錯誤的直接原因,因爲我擁有所有正確的名稱空間和dll。但是,當我停止使用自己的自定義KeyValuePair類並使用標準的KeyValuePair類時,問題就消失了。我懷疑這個問題與我的類實現IEnumerable和IEnumerable >有關。 –