It’s even possible but you need to understand that the idea of LINQ is the functional programming style that preaches immutability. And the name itself demonstrates this. Q is from query, of consultation, and not manipulation, updating.
So although it is possible using some confusing technique, it goes against the intention of the resource and it is better to use the traditional algorithm to do the manipulation. You can even use LINQ to determine all collection elements that meet the established condition and deserve manipulation and then manipulate into a foreach
. Many will prefer to do the consultation and manipulation on within the foreach
. In this case it is so simple that LINQ is disposable.
foreach (var item in clientes) item.NomeFantasia.Replace("*", "");
Or if you want to just start:
foreach (var item in clientes) item.NomeFantasia.TrimStart('*');
I don’t know if I fully understand your goal but it’s that simple. Even if you want to do something a little different, the basis is this. Of course, LINQ can still be used to make other filters. But if it is related it is probably best to put a if
within the foreach
even.
If you insist:
var resultado = clientes.Select(item => { item.NomeFantasia.TrimStart('*'); return item; })
I put in the Github for future reference.
But note that the update will not run at this time. It is characteristic of LINQ to have a delayed execution.
I found no LINQ shorter :)
I don’t understand yet... You want to receive the data and then change it in the original collection or only in the result?
– RSinohara