Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List contains in List check

Tags:

c#

.net

linq

I have a IEnumerable<Object> a with 6 items in chronological order in it. I want to test if list IEnumerable<Object> b with 3 items in chronological order.

IEnumerable<Object> a item values: a,b,c,d,f,g

IEnumerable<Object> b item values: b,d,f

Is it possible to be done with LINQ ?

like image 205
eugeneK Avatar asked Nov 29 '22 13:11

eugeneK


1 Answers

You can use the following:

bool AContainsEverythingInBInTheSameOrder =
    a.Intersect(b).SequenceEquals(b);

a.Intersect(b) returns everything that is in both a and b, in the same order in which it appears in a.

like image 52
Rawling Avatar answered Dec 02 '22 01:12

Rawling