如何在f#中的类中定义私有静态方法?当我尝试附加私人修饰符时,它会抱怨。
答案 0 :(得分:13)
这是一个定义和使用私有静态成员的简短脚本:
type MyClass =
static member private MyPrivateMember() = printfn "MyPrivateMember()"
static member MyMember() = MyClass.MyPrivateMember()
MyClass.MyMember() // MyPrivateMember()
答案 1 :(得分:5)
替代方案:
type MyClass () =
static let myPrivateMethod () =
printfn "This is inaccessible outside the class."