什么是从F#调用DateTime.TryParse正确的方法是什么?我想,以测试从F#交互式约code和我想不出如何通过一个可变的日期时间到由裁判第二个参数。什么是F#的输入/输出/ REF语法?
What is the correct way to call DateTime.TryParse from F#? I am trying to test some code from F# interactive and I can't figure out how to pass a mutable DateTime into the second argument by ref. What is the in/out/ref syntax in F#?
这是方法的签名我看: http://msdn.microsoft.com/en-us/library/ch92fbc1.aspx?cs-save-lang=1&cs-lang=fsharp#$c$c-snippet-1
This is the method signature I'm looking at: http://msdn.microsoft.com/en-us/library/ch92fbc1.aspx?cs-save-lang=1&cs-lang=fsharp#code-snippet-1
克里斯的答案是正确的,如果你真的需要通过一个可变的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.