查找2个列表

本文关键字:列表 2个 查找 | 更新日期: 2023-09-27 17:50:32

在我的程序中我有两个列表:

List<string> aaa = new List<string>();
List<string> bbb = new List<string>();

在列表aaa中我有像(1 2 3 4)这样的数字。在列表BBB中我有像(0 1 0 1)这样的数字。

现在我需要检查列表aaa上的索引是否为空。之后,我需要得到索引的值(如果不是空的)。然后在相同的aaa.index上检索BBB上的值。

我使用

:

var exist = aaa.Find(x => x == "2");

查找2个列表

var inx = aaa.IndexOf("2");
if (inx >= 0)
{
    var result = bbb[inx];
}