I have a collection of objects objcol1(example Collection of cities in a state) and another object collection objcol2(example collection of cities in a country). Now I am querying for objcol1 and I want to add it to objcol2. I can do this by iterating through objcol1 and adding one by one to objcol2 but can I directly add objcol1 to objcol2 like
objcol2.add(objcol1);
Can anyone tell me whether it is possible without iterating? If yes please explain me the process
You could use the
Enumerable.Concatextension method:I’m sure under the covers somewhere it actually iterates, but you won’t need to write the code to do it.
NOTE: This will only work if your
Cityobjects are the same, alternatively you could useSelectto map the objects.