0
string[] words1 = new string[] {
        "How are you?", 
        "Where are you?"
    };

string[] words2 = new string[] {
        "I'm fine.", 
        "I'm outside."
     };

// how do I perform an action by showing the indexes are same
if (words1[0] == words2[0]) // I'm stuck here
{
    // an action will be executed.
}
4

1 回答 1

-1

当你想检查两个数组的长度时,你可以使用 length 属性

if (words1.Length == words2.Length)

要检查 words1 数组中的单词是否也存在于 words2 中,您可以使用 linq。遍历 words1 中的所有单词并检查 words2 数组中是否有一个等于。不返回false时

foreach (var word1 in words1)
{
    bool word1ExistsInWords2 = words2.FirstOrDefault(word2 => word2 == word1) == null ? false : true;
}
于 2019-05-03T08:22:59.733 回答