Is it somehow possible to use the ‘With’ keyword on an existing object?
I would like to do the following using LINQ to objects and can’t seem to find a way:
From m as Product in Me _
Select m With {.Match = m.Name.IndexOf(query)} _
Where m.Name.IndexOf(query) > 0
No there is no way of doing this (
Withcan only be used with a constructor). It would violate the functional principles on which linq is built, specifically that there will not be side-effects.Best bet is to create a new Product in your select with the Match property set.