Here is the starting code:
Dictionary<string,object> dest=...;
IDictionary<string,object> source=...;
// Overwrite in dest all of the items that appear in source with their new values
// in source. Any new items in source that do not appear in dest should be added.
// Any existing items in dest, that are not in source should retain their current
// values.
...
I can obviously do this with a foreach loop that goes through all of the items in source, but is there some shorthand way to do this in C# 4.0 (perhaps LINQ)?
Thanks
The
foreachis pretty small. Why complicate things?If you’re going to repeat this often, you could write an extension method:
As for doing it “with LINQ”, the query part means that a LINQ method should have no side effects. Having side effects is often confusing to those of us who expect no side effects from it.