How to neatly query corresponding object array items?

后端 未结 1 1675
梦毁少年i
梦毁少年i 2021-01-23 08:38

I have an array of objects that\'ll be used for some process.

var x = new List() { new MyObject(), new MyObject(), ... }.ToArray();
相关标签:
1条回答
  • 2021-01-23 09:35

    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.

    0 讨论(0)
提交回复
热议问题