【发布时间】:2016-10-12 10:16:32
【问题描述】:
我想使用 linq 更新链表中的节点值。遍历列表,找到正确的节点并更新值是可行的,但我认为 linq 方法可能更干净。
这是我的尝试,它给出了编译错误cannot convert lambda expression to type <Main.Globals.Node> because it is not a delegate type:
// get IV value where Node BookID=4
var val = Globals.BookLL.Where(B => B.BookID == 4).Select(B => B.IV).Single();
// can update first node using this method
Globals.BookLL.First.Value.IV = 999;
// can upddate IV by traversing list
LinkedListNode<Globals.Node> Current = Globals.BookLL.First;
while (Current != null)
{
if(Current.Value.BookID==4)
{
Current.Value.IV = 444;
}
Current = Current.Next;
}
// how can you update IV using linq?
Globals.BookLL.Find(B => B.BookID == 4).Value.IV = 999; // cannot convert lambda expression to type <Main.Globals.Node> because it is not a delegate type
感谢您的帮助。
【问题讨论】:
-
如果是Linq方法,应该调用
First:Globals.BookLL.First()
标签: c# linq linked-list find