检查两个字符串数组的等价性

Gro*_*ile 2 c#

有没有更好的方法来检查两个字符串数组是否具有相同的内容?

string[] first = new string[]{"cat","and","mouse"};
string[] second = new string[]{"cat","and","mouse"};

bool contentsEqual = true;

if(first.Length == second.Length){
    foreach (string s in first)
    {
        contentsEqual &= second.Contains(s);
    }
}
else{
    contentsEqual = false;
}


Console.WriteLine(contentsEqual.ToString());//    true
Run Code Online (Sandbox Code Playgroud)

Yur*_*ich 6

Enumerable.SequenceEquals,如果它们应该是相同的顺序.