Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C#中有没有紧凑而优雅的方法可以同时遍历两个列表?_C#_.net_Algorithm_Linq - Fatal编程技术网

在C#中有没有紧凑而优雅的方法可以同时遍历两个列表?

在C#中有没有紧凑而优雅的方法可以同时遍历两个列表?,c#,.net,algorithm,linq,C#,.net,Algorithm,Linq,因此,我有一些代码,我做的东西像 List<ParameterInfo> theseParams = this.Action.GetParameters().OrderBy(p => p.Name).ToList(), otherParams = other.Action.GetParameters().OrderBy(p => p.Name).ToList(); if(thesePa

因此,我有一些代码,我做的东西像

        List<ParameterInfo> theseParams = this.Action.GetParameters().OrderBy(p => p.Name).ToList(),
                            otherParams = other.Action.GetParameters().OrderBy(p => p.Name).ToList();
        if(theseParams.Count != otherParams.Count)
            return false;
        for(int i = 0; i < theseParams.Count; ++i)
        {
            ParameterInfo thisParam = theseParams[i],
                          otherParam = otherParams[i];
            if(thisParam.Name != otherParam.Name)
                return false;
        }
        return true;
List theseParams=this.Action.GetParameters().OrderBy(p=>p.Name.ToList(),
otherParams=other.Action.GetParameters().OrderBy(p=>p.Name.ToList();
如果(theseParams.Count!=其他Params.Count)
返回false;
对于(int i=0;i
我想知道是否有一种紧凑的方法可以一次遍历列表?

当然,只需使用and

当然,只要使用和


签出签出导入注意,这不会处理
如果(theseParams.Count!=otherParams.Count)
检查,则该部分仍需要在代码中。Zip的行为类似于(int i=0;i@ScottChamberlain遗漏了这一点,现已修复。尽管问题重复,但此答案值得投票:)Importnat注意,如果(theparams.Count!=otherParams.Count)
检查,则不处理
,这一部分仍然需要在代码中。Zip的行为类似于for的
(int i=0;i
@ScottChamberlain遗漏了这一点,现已修复。尽管问题重复,但这个答案值得投票:)
return theseParams.Count == otherParams.Count
    && theseParams.Zip(otherParams, (t,o) => new {These = t, Other =o})
    .All(x => x.These.Name == x.Other.Name);