I have two arrays idxListResponse & _index both of which have the same structure.
Each of these arrays contains a number of elements with different properties one of which is a child array called indexdata
Each element of this array has a number of properties one of which is another array called datafield. This has a number of key value pair properties.
So in essence I have a hierarchy of 3 separate arrays.
I'm looking to get the first level of the hierarchy + all elements of the 2nd level where the 3rd level items don't match, i.e. exclude only those items from the 2nd level where the 3rd level items are a match.
I've tried approaching this a number of different ways but so far I'm not getting anywhere, could anyone help.
FYI - here's my latest attempt
var q = idxListResponse.Index.Where(a =>
a.IndexData.All(b =>
b.DataField.All(c =>
_index.Index.Where(z =>
z.IndexData.All(y => y.DataField.Contains(c.name))
)
)
)
);
Except
is a good way of doing that:
var items = source1.Except(source2);
Would return all items in source1
except those in source2
.
Since your collections appear to be different types, you would do something like:
source1.Except(source2.Select(s => /* selector here */))
Or you could create your own implementation of IEqualityComparer
and use that to compare the two different types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With