繁体   English   中英

在F#中传递`out`参数(作为参考)

[英]Pass `out` parameter (as reference) in F#

我想调用System.Uri.TryCreate()

let uriResult: System.Uri = ref (* what's here? *);
System.Uri.TryCreate(uriName, UriKind.Absolute, uriResult)

正如我在这里学到的,必须为.NET 输出参数传递F#参考。

但是我如何在我的情况下初始化我的参考uriResult

我试过创建一个新的空Uri对象。

let uriResult: System.Uri = ref (new System.Uri());

错误1
该表达式预计具有类型
乌里
但这里有类型
'参考

如MSDN上的参数和参数中所述(请参阅按引用传递),out参数会自动进行tuplized,因此您可以执行以下操作:

match System.Uri.TryCreate(uriName, UriKind.Absolute) with
| true, uriResult -> //OK
| _ -> //not a Uri

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM