I have a large nested that selects new classes, which works good, but I would like to Add a new KeyValuePair to the “TestDictionary” on the fly, that has value from “B”.
from a ... from b ...
select new c
{
TestC = b.Foo,
TestDictionary = new Dictionary(b.Parameters.ToDictionary(
x => x.ParameterKey, x => (object)x.ParameterValue))
// .Add(new.. "SomeKey", b.SomeValue) ?
}).ToList()
Tried to use the Add method, but cant get it to work. Is it possible to Add one keyvaluepair to the newly created dictionary on the fly?
Thanks in advance
/Lasse
You should be able to use the collection initializer syntax. When the
Add()method takes more than one parameter, as with aDictionary, you wrap each in curly braces: