Merge 2 lists using query syntax

  • Thread starter Thread starter Sems
  • Start date Start date
S

Sems

Hi

I'm trying to add the items in one list to another list using query
syntax. This is what I have so far...

MyList.ForEach(c => MyOtherList.Add(bc));

Is this the best way to do it?

Thanks
 
I'm trying to add the items in one list to another list using query
syntax. This is what I have so far...

MyList.ForEach(c => MyOtherList.Add(bc));

Is this the best way to do it?

MyOtherList.AddRange(MyList);

has been in .NET forever.

If you need it as returning an expression, then one of the
LINQ methods:

MyList.Union(MyOtherList)

or:

MyList.Concat(MyOtherList)

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top