Güven Acar Güven Acar - 1 year ago 91
Vb.net Question

Change all values of a list with new with linq

Perhaps very eash but i dont know linq.

I have a integer list

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

I want change some values with new e.g. 90 with 80

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

How can i do? Thanks

Answer Source

One way is to use Select, like this:

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>) will produce 80 when the corresponding item is 90; otherwise, it will produce the unchanged item itself.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download