I have a list contains many Blocks, and the Blocks are divided into old ones and new ones, using a property ‘IsOld’ in class ‘Block’ to specify them. Now I extract the old ones like this:
List<Block> olds = blocks.Where(item => {return item.IsOld;}).ToList();
and after I change some values of the properties on the items in ‘olds’ list, the corresponding ones in the original list ‘blocks’ do not change. And I don’t know how to deal with it. And that means if I use List.Where method, it will make a deep copy for every item?
‘Block’ is a struct and I first thought it was a class.
so sorry to trouble you because of my careless o(︶︿︶)o
You are saying that you are changing values of properties, and not replacing the objects themselves. Therefore the original objects in the blocks list should also be updated, that is if Block is defined as a class-type. If Block is a struct, than every assignment is done in a copy of the original object, and then your changes in the olds list should not be reflected in the original blocks list.
Is Block a struct?