我不認爲我實際上可以將字段(列)添加到現有的IEnumerable中。但我想要的是從現有的具有計算字段的IEnumerable派生的新IEnumerable。 WebMatrix使用網頁中的僞代碼看起來像:在c#中添加一列到IEnumerable中#
var db = Database.Open("LOS");
var ie = db.Query(sqlAssignments);
// make a new ie2 that has an extra field
// ??? ie2 <=== ie with new field c = ie.a + ie.b
var grid = new WebGrid(ie2, extra parameters);
我知道如何做循環通過ie中的所有行。但我希望有更優雅的東西。
的IEnumerable只是表示一個枚舉類型,即消費者可以枚舉通過它的組成項目。它沒有'領域'或'專欄'的概念。 – 2011-03-17 11:45:16
@亞當 - 但我認爲更多的人可能會理解*標題,比如:「使用投影創建基於舊序列的新序列,但使用額外的成員」... – 2011-03-17 11:48:26