开发者

simple c# class to f#

开发者 https://www.devze.com 2023-02-01 06:25 出处:网络
How would this class look in f#? public class myClass : baseClass { public myClass() { this.someVariable = \"test\";

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()
0

精彩评论

暂无评论...
验证码 换一张
取 消