2016-11-22 35 views
0

也许很容易,但我不知道linq。用linq更改新列表的所有值

我有一个整数列表

Dim IntList As list (Of Integer) = {90,45,66,66,7,90,20}.tolist 

我想改变与新例如一些值90 with 80

IntList = {80,45,66,66,7,80,20} 

我该怎么办?感谢

+1

Linq是_querying_ not _updating_。如果你想在原地改变列表,使用'For'循环。 Linq可以创建一个_new_列表。 –

+0

但是如何?我不知道linq –

回答

3

的一种方式是使用Select,像这样:

Dim Seq = From n In IntList Select If (n=90, 80, n) 
Dim Subst As List (Of Integer) = Seq.ToList() 

If(<cond>, <on-true>, <on-false>)将产生80当对应的产品90;否则,它会自己产生不变的项目。

+0

谢谢。工作。 –

1

几乎没有改变dasblinkenlight的答案。

IntList = IntList.Select(Function(x) If(x = 90, 80, x)).ToList