Intersection of two string array (ignore case)

后端 未结 1 1065
灰色年华
灰色年华 2020-12-10 00:13

I have two arrays:

string[] array1 = { \"Red\", \"blue\", \"green\", \"black\" };
string[] array2 = { \"BlUe\", \"yellow\", \"black\" };

I

相关标签:
1条回答
  • 2020-12-10 00:51

    How about an Enumerable.Intersect and StringComparer combo:

    // other options include StringComparer.CurrentCultureIgnoreCase
    // or StringComparer.InvariantCultureIgnoreCase
    var results = array1.Intersect(array2, StringComparer.OrdinalIgnoreCase);
    
    0 讨论(0)
提交回复
热议问题