如何在F#中使用SequenceEqual和StringComparer.OrdinalIgnoreCase?

时间:2015-05-13 20:55:06

标签: .net linq f#

在C#中,我有这段代码:

string[] words =  { "how", "are", "you" };
string[] words2 = { "HOW", "are", "YOU" };

var result = words.SequenceEqual(words2, StringComparer.OrdinalIgnoreCase);

result的值为true。

在F#中,我想做同样的事情:

let words =  [|"how", "are", "you"|]
let words2 = [|"HOW", "are", "YOU"|]

let result = words.SequenceEqual(words2, StringComparer.OrdinalIgnoreCase)

但编译器抱怨:

  

StringComparer类型与Collections.Generic.IEqualityComparer<string * string * string>

类型不兼容

如何在F#中使用StringComparer.OrdinalIgnore作为我的示例?

1 个答案:

答案 0 :(得分:4)

您需要使用;来分隔数组元素:

let words =  [|"how"; "are"; "you"|]
let words2 = [|"HOW"; "are"; "YOU"|]

,用于分隔元组中的元素,因此您当前有两个包含类型为string * string * string的3元素元组的1元素数组。