I have the following which is an array
package.Resources
If I use
package.Resources.ToList().Add(resouce);
package.Resources doesn’t actually contain the new item.
I have to use
var packageList = package.Resources.ToList();
packageList.Add(resource);
package.Resources = packageList.ToArray();
Why is that?
ToList()creates a completely new, different list based on the original array.LINQ is read-only; Language INtegrated Query – it is only querying the data, not modifying it. All LINQ methods produce a projection – e.g., they project the original sequence into a new one, so you’re always working against that.