How to "interleave" two DataTables.

Posted by Brent on Stack Overflow See other posts from Stack Overflow or by Brent
Published on 2010-06-10T02:23:17Z Indexed on 2010/06/10 2:32 UTC
Read the original article Hit count: 438

Filed under:
|
|

Take these two lists:

List 1

Red Green Blue

List 2

Brown Red Blue Purple Orange

I'm looking for a way to combine these lists together to produce:

List 3

Brown Red Green Blue Purple Orange

I think the basic rules are these:

1) Insert on top the list any row falling before the first common row (e.g., Brown comes before the first common row, Red);

2) Insert items between rows if both lists have two items (e.g., List 1 inserts Green between Red and Blue); and

3) Insert rows on the bottom if the there's no "between-ness" found in 2 (e.g., List 2 inserts Orange at the bottom).

The lists are stored in a DataTable. I'm guessing I'll have to switch between them while iterating, but I'm having a hard time figuring out a method of combining the rows.

Thanks for any help.

--Brent

© Stack Overflow or respective owner

Related posts about c#

Related posts about merge