문제

How would this class look in f#?

public class myClass : baseClass
{
    public myClass()
    {
        this.someVariable = "test";
        this.someFunction();
    }
}

So far i've figured out (is it even correct?):

type myClass = class
        inherit baseClass
        new ()= 
            this.someFunction()
end

but am struggling with calling someFunction() as it says 'this' is not defined

도움이 되었습니까?

해결책

Here's one way to translate your code:

type baseClass() =
    member this.someFunction() = printf "hello world\n"

type myClass() as this =
    inherit baseClass()
    let mutable someVariable = "test"
    do this.someFunction()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top