Replace an object in a list of objects

You have to replace the item, not the value of customListItem2. Just replace following: customListItem2 = customListItems.Where(i=> i.name == “Item 2”).First(); customListItem2 = newCustomListItem; With this: customListItem2 = customListItems.Where(i=> i.name == “Item 2”).First(); var index = customListItems.IndexOf(customListItem2); if(index != -1) customListItems[index] = newCustomListItem; Edit: As Roman R. stated in a comment, you can replace the … Read more

Is it possible to have tuple assignment to variables in Scala? [duplicate]

This isn’t simply “multiple variable assignment”, it’s fully-featured pattern matching! So the following are all valid: val (a, b) = (1, 2) val Array(a, b) = Array(1, 2) val h :: t = List(1, 2) val List(a, Some(b)) = List(1, Option(2)) This is the way that pattern matching works, it’ll de-construct something into smaller parts, … Read more

Unexpected behaviour with a conditional generator expression [duplicate]

Python’s generator expressions are late binding (see PEP 289 — Generator Expressions) (what the other answers call “lazy”): Early Binding versus Late Binding After much discussion, it was decided that the first (outermost) for-expression [of the generator expression] should be evaluated immediately and that the remaining expressions be evaluated when the generator is executed. […] … Read more