如何提取Int32和Int64类型的方法?

时间:2018-10-04 19:39:59

标签: f#

如何抽象化Int32和Int64类型的方法?

具体来说,如何将这些相似的函数重构为核心函数?

let private tryParseInt64 (text:string) =

    let mutable (number:Int64) = 0L

    if Int64.TryParse(text, ref number)
    then Some number
    else None

let private tryParseInt32 (text:string) =

    let mutable (number:Int32) = 0

    if Int32.TryParse(text, ref number)
    then Some number
    else None

0 个答案:

没有答案