在列表中找到三项匹配的元组

Wil*_*son 2 c# string indexing tuples wildcard

我需要的指数Tuple<string,string,string,string>List三个给定的项目,但不要紧第四个是什么。例如:

Listoftuples.IndexOf(new Tuple<string,string,string,string>("value1","value2","value3","this value does not matter"))
Run Code Online (Sandbox Code Playgroud)

索引是否有通配符,或者有其他解决方法?

Lee*_*Lee 5

int index = Listoftuples.FindIndex(t => t.Item1 == "value1" && t.Item2 == "value2" && t.Item3 == "value3");
Run Code Online (Sandbox Code Playgroud)

您可能要创建一个函数来创建谓词:

Func<Tuple<string,string,string,string>, bool> CreateMatcher(string first, string second, string third)
{
    return t => t.Item1 == first && t.Item2 == second && t.Item3 == third;
}
Run Code Online (Sandbox Code Playgroud)

那么你可以使用

int index = Listoftuples.FindIndex(CreateMatcher("value1", "value2", "value3"));
Run Code Online (Sandbox Code Playgroud)