我正把头靠在墙上试图想出办法。我已经分解了我想在最简单的解释中弄清楚的内容,如下所示:
假设我有这两个字符串数组,其中包含以下数据:
string[] firstName = new string[2];
string[] lastName = new string[2];
firstName[0] = "John";
firstName[1] = "Jane";
lastName[0] = "Doe";
lastName[1] = "Doe";
然后我有一个方法将这个数组传递到:
private void Matches(IEnumerable<string> firstNames, IEnumerable<string> lastNames)
{
}
然后我有两个变量:
string myFirstName = "John";
string myLastName = "Doe";
如何在Matches方法中使用Linq查找传入名称的完全匹配? (不幸的是,Matches方法的标题必须保持原样)基于该数据,我能找到匹配项吗?我正试着弄清楚这个......我笑了。大笑
答案 0 :(得分:1)
将两者拼凑在一起,然后只做一个简单的Where
:
var myName = myFirstName + " " + myLastName;
firstNames.zip(lastNames, (first, last) => first + " " + last)
.Where(fullName=>fullName == myName)