Assigning values inside a LINQ Select?

后端 未结 3 1274
小蘑菇
小蘑菇 2020-12-06 16:36

I have the following query:

drivers.Select(d => { d.id = 0; d.updated = DateTime.Now; return d; }).ToList();

drivers is a List which com

3条回答
  •  清歌不尽
    2020-12-06 17:07

    NEVER DO THIS. A query should be a query; it should be non-destructively asking questions of a data source. If you want to cause a side effect then use a foreach loop; that's what it's for. Use the right tool for the job.

提交回复
热议问题