The two lists are like
LISTONE "ONE", "TWO", "THREE"
LISTTWO "ONE", "TWO", "THREE"
i need to compare the whether the items in two lists are in same order or not.
Is there any way to do this in LINQ
The two lists are like
LISTONE "ONE", "TWO", "THREE"
LISTTWO "ONE", "TWO", "THREE"
i need to compare the whether the items in two lists are in same order or not.
Is there any way to do this in LINQ
Maybe:
bool equal = collection1.SequenceEqual(collection2);
See also: http://stackoverflow.com/questions/50098/comparing-two-collections-for-equality
List<string> list1;
List<string> list2;
bool sameOrder = list1.SequenceEqual(list2);
Determine if both lists contain the same data in same order:
bool result = list1.SequenceEqual(list2);
Same entries in different order:
bool result = list1.Intersect(list2).Count() == list1.Count;
Greets Flo
These are the correct answers, but as a thought, If you know the lists will have the same data but may be in different order, Why not just sort the lists to guarantee the same order.
var newList = LISTONE.OrderBy(x=>x.[sequence]).ToList();
If you know there can't be duplicates:
bool result = a.All(item => a.IndexOf(item) == b.IndexOf(item));
Otherwise
bool result = a.SequenceEquals(b)