所以我有几段代码,我会像
那样做 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;
我想知道是否有一种紧凑的方法可以立即迭代到列表?
答案 0 :(得分:4)
当然只需使用Enumerable.Zip
和Enumerable.All
。
return theseParams.Count == otherParams.Count
&& theseParams.Zip(otherParams, (t,o) => new {These = t, Other =o})
.All(x => x.These.Name == x.Other.Name);