如何从List中选择记录并根据条件移动到其他列表,并将记录逐个复制到其他列表中。 [英] How to select records from List and move to other list on basis of condition and copy the record into other List one by one.

查看:99
本文介绍了如何从List中选择记录并根据条件移动到其他列表,并将记录逐个复制到其他列表中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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





这不过是第一个列表的第一个记录。



我想要运行一个foreach循环,其中我必须逐个选择第二个列表中存在ID的所有记录并将其保存到其他新列表。



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.

推荐答案

我想你想做什么是:

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


这篇关于如何从List中选择记录并根据条件移动到其他列表,并将记录逐个复制到其他列表中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆