Click here to Skip to main content
15,936,903 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I ahve Firstlist with this record :


And other secondlist with:

That is nothing but the first record of the first list.

NOw i want to run a foreach loop, in which i have to selct all the record with ID present in the secondList one by one and save it to other New list.
Updated 27-Nov-15 5:37am
OriginalGriff 27-Nov-15 10:02am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Perhaps an example of what you are trying to generate would help - along with the relevant code fragments to show us what you have tried so far?
Use the "Improve question" widget to edit your question and provide better information.
Nawab Ahmad 27-Nov-15 10:06am    
foreach(list lc in secondlist)
create new list and add the record the value to it

so we have to value in secondlist,
so we have to find the matching record from Firstlist and insert into new list,
so we will get two new list because we have to different first column name(NAWA01
[no name] 27-Nov-15 11:10am    
When you asking any question please try to give sufficient info to users for getting better response. Because we don't know what is your exact requirement.

What is the value you need as output. Provide details.
Patrice T 27-Nov-15 14:58pm    
And where is the problem ?

1 solution

I think what you want to do is:
List<string> FirstList = new List<string>();  // contains the 4 records
List<string> Ids = new List<string>();        // contains IDs of interest
List<string> ThirdList = new List<string>();  // list to receive the records of interest

foreach (string id in Ids) {
    foreach (string rec in FirstList) {
        if (rec.StartsWith (id)) {
            ThirdList.Add (rec);
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900