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

Com*_*eek 5 .net f# functional-programming reference

我想打电话System.Uri.TryCreate():

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

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

但是如何uriResult在我的案例中初始化我的参考?

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

let uriResult: System.Uri = ref (new System.Uri());
Run Code Online (Sandbox Code Playgroud)

错误1
此表达式应具有类型
     Uri,
但此处的类型为
    "a ref"

Dan*_*iel 11

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

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