小编cry*_*der的帖子

需要有关将C#转换为F#的帮助

我需要帮助翻译IndexOfAny for string的自定义扩展,因为现有框架没有匹配字符串值的IndexOfAny.已经翻译了我自己的.但是我不知道如何通过返回值突破循环.任何想法如何摆脱循环或更好的解决方案.以下是我的翻译.

C#

public static int IndexOfAnyCSharp(this string str, string[] anyOff) {
    if (str != null && anyOff != null)
        foreach (string value in anyOff) {
            int index = str.IndexOf(value);
            if (index > -1) return index;
        }
    return -1;
}
Run Code Online (Sandbox Code Playgroud)

F#

[<Extension>]
static member public IndexOfAnyFSharp(str:string, anyOff:string[]) =
    match str <> null && anyOff <> null with
    | true ->
        let mutable index = -1
        for value in anyOff do
            if index = -1 then
                index <- str.IndexOf(value)
        index …
Run Code Online (Sandbox Code Playgroud)

f# c#-to-f#

4
推荐指数
1
解决办法
170
查看次数

标签 统计

c#-to-f# ×1

f# ×1