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

NAWA01|N0475|57|20100401|20151231
NAWA01|N7511|154|20120801|20151231
NAWA03|N7780||19980101|20151231
NAWA03|N9120||20070101|20151231


And other secondlist with:
NAWA01
NAWA03


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.
Posted
Updated 27-Nov-15 5:37am
v2
Comments
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    
Example:
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
NAWA03)
[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);
        }
    }
}
/ravi
 
Share this answer
 
v2

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