我有两个数组:
string[] array1 = { "Red", "blue", "green", "black" };
string[] array2 = { "BlUe", "yellow", "black" };
我需要在一个数组中仅匹配字符串(忽略大小写)。
结果应该是:
string[] result = { "blue", "black" } or { "BlUe", "black" };
我有两个数组:
string[] array1 = { "Red", "blue", "green", "black" };
string[] array2 = { "BlUe", "yellow", "black" };
我需要在一个数组中仅匹配字符串(忽略大小写)。
结果应该是:
string[] result = { "blue", "black" } or { "BlUe", "black" };
可以试试使用 Enumerable.Intersect
和 StringComparer
的组合:
// other options include StringComparer.CurrentCultureIgnoreCase
// or StringComparer.InvariantCultureIgnoreCase
var results = array1.Intersect(array2, StringComparer.OrdinalIgnoreCase);
results
) 将包含来自array1
而非array2
的值。 - Neo