Question

So I have this class in C#:

public class Foo : IFoo {
    public bool TryConnect(out Status status) {
        ...
    }
}

And I want to consume it with F#.

Unfortunately I had to use some hackery such as:

type FooService (foo : IFoo) =

    member x.Execute() =
        let mutable status = Unchecked.defaultof< ^Status>
        foo.TryConnect(&status) |> ignore
        (...do something with status...)

Is there a way to not use "mutable" here? In the end, I'm not actually using the first initialization value at all.

(I'm using F# 2.0, but if you have hints that only apply to F# 3.0, I'll be happy to hear them.)

Thanks

Était-ce utile?

La solution

out params are automatically tuplized. So, you can do:

let res, status = foo.TryConnect()

For more info, see Passing by Reference on MSDN.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top