7

I want to call System.Uri.TryCreate():

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

As I've learned here, one has to pass a F# reference for .NET out parameters.

But how can I initialize my reference uriResult in my case?

I've tried creating a new, empty Uri object.

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

Error 1
This expression was expected to have type
     Uri
but here has type
    'a ref

Community
  • 1
  • 1
ComFreek
  • 29,044
  • 18
  • 104
  • 156

1 Answers1

14

As explained in Parameters and Arguments on MSDN (see Passing by Reference), out parameters are automatically tuplized, so you can do this:

match System.Uri.TryCreate(uriName, UriKind.Absolute) with
| true, uriResult -> //OK
| _ -> //not a Uri
ComFreek
  • 29,044
  • 18
  • 104
  • 156
Daniel
  • 47,404
  • 11
  • 101
  • 179