什么是从F#调用DateTime.TryParse正确的方法是什么? [英] What is the correct way to call DateTime.TryParse from F#?

查看:316
本文介绍了什么是从F#调用DateTime.TryParse正确的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是从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#?

这是方法的签名我看: <一href="http://msdn.microsoft.com/en-us/library/ch92fbc1.aspx?cs-save-lang=1&cs-lang=fsharp#$c$c-snippet-1">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.

这篇关于什么是从F#调用DateTime.TryParse正确的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆