-3
foreach (var item in items)
{
    item.category = "All Items";
}

How to replace the above foreach with Linq.

I have tried with following code, but it returns null for the item

_ = items.Select(x => x.item = "All Items")

Note : items is of type IEnumerable<ItemList>

Earth
  • 3,477
  • 6
  • 37
  • 78

1 Answers1

0

linq is an example of functional programming - in general it does not change the input data it reads it in and outputs new data

you can do this (assuming you have a List to start with)

 items = items.Select(item=>new {category="All Items", x=.., y=..}).ToList()

wher x and y are the other fields in ItemList

pm100
  • 48,078
  • 23
  • 82
  • 145