You could also use Except(produces the set difference of two sequences) to check whether there's a difference or not:
IEnumerable inFirstOnly = a1.Except(a2);
IEnumerable inSecondOnly = a2.Except(a1);
bool allInBoth = !inFirstOnly.Any() && !inSecondOnly.Any();
So this is an efficient way if the order and if the number of duplicates does not matter(as opposed to the accepted answer's SequenceEqual
). Demo: Ideone
If you want to compare in a case insentive way, just add StringComparer.OrdinalIgnoreCase
:
a1.Except(a2, StringComparer.OrdinalIgnoreCase)