我試圖生成表單的圖表:LINQ:用匿名類型處理
User A User B Owes Owed Net
Sam David $20 $10 $10
Timbo ODP $30 $0 $30
使用下面的查詢:
var debt = from user in users
select new {
Username = username,
User = user,
Owes = owedBetween(username, user),
Owed = owedBetween(user, username),
Net = Owes - Owed // doesn't compile
};
的問題是,最後行不編譯。有沒有辦法在查詢中設置Net
值,還是必須將其初始化爲零,然後再進行更改?
+1優雅..... – CesarGon 2010-10-10 14:34:58
+1:'let'正是我們所需要的。 – Ani 2010-10-10 14:35:28