我有一个会被用于一些工艺对象的数组
I have an array of objects that'll be used for some process.
var x = new List<MyObject>() { new MyObject(), new MyObject(), ... }.ToArray();
的处理之后,返回对应于每个输入对象的结果的数组。
After the process, it returns an array of results corresponding to each of the input objects.
var y = MyProcess(x); // returns List<MyResult>现在,我的问题是我如何可以查询给定的条件结果列表和相应的输入对象?
Now, my question is how can I query a list of results with a given condition and the corresponding input objects?
例如,如果 Y [2] .IsOkay 是假,我想同时获得 X [2] 和 Y [2] 在另一个数组。 和数组x和y的对象没有除指数的参考项。
For example, if y[2].IsOkay is false, I want to obtain both x[2] and y[2] in another array. And the objects in array x and y don't have a reference key except the index.
推荐答案好了,您可以使用 邮编 配对起来:
Well, you can use Zip to pair them up:
var pairs = x.Zip(y, (a, b) => new { a, b }) .Where(pair => !pair.b.IsOkay) .ToArray();您可以更改传递给邮编委托如果你想以不同的方式组成两个值 - 例如,使用一个名为类型,而不是匿名类型我上面有
You can change the delegate passed to Zip to compose the two values differently if you want - for example, using a named type instead of the anonymous type I've got above.
更多推荐
如何巧妙地查询相应的对象数组项?
发布评论