List<object> list = new List<object>();
while (myReader.Read())
{
string arrKablan = myReader["arrK_Title"].ToString();
string arrTotal = myReader["arrTotal"].ToString();
string _title = myReader["MF_Title"].ToString();
string _path = myReader["MF_Path"].ToString();
int _level = Convert.ToInt32(myReader["MF_Level"].ToString());
list.Add(new { title = _title, path = _path, kablanim = arrKablan, total = arrTotal, level = _level });
}
,我需要選擇只是其中的物品級別== 1
我試圖
list = list.where(item => item.level == 1);
,但我得到一個錯誤
'object' does not contain a definition for 'level' and no extension method 'level' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
我知道編譯器可以得到這個類型,這樣他就可以知道它是什麼「級別」了。 我怎樣才能實現這種選擇,而不需要定義一個類?
真正的問題會被你爲什麼不*想*定義一個類型? – Crono 2015-02-24 13:35:51
界面將如何幫助我?\ – eyalb 2015-02-24 13:37:49
剛剛編輯了評論。暫時忘記接口。否則,我們可能會對裝飾器/包裝器模式做出太詳細的闡述。 – Crono 2015-02-24 13:41:35