且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

什么是从F#调用DateTime.TryParse正确的方法是什么?

更新时间:2023-11-29 13:46:40

克里斯的答案是正确的,如果你真的需要通过一个可变的DateTime 参考。但是,在很多F#更地道使用编译器的能力,把尾随退出参数tupled返回值:

Chris's answer is correct if you really need to pass a mutable DateTime by reference. However, it is much more idiomatic in F# to use the compiler's ability to treat trailing out parameters as tupled return values:

let couldParse, parsedDate = System.DateTime.TryParse("11/27/2012")

在这里,首先看重的是布尔返回值,而第二个是分配出去的参数。

Here, the first value is the bool return value, while the second is the assigned out parameter.