How to choose between private member and let binding?

后端 未结 3 1797
陌清茗
陌清茗 2021-01-17 21:29

When writing a private method that has no need to access other members of the same class, how do you choose between private member and let binding?

  • I tend to u
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-17 21:57

    let bindings cannot be accessed through the class instance but private method can. For examples:

    type A() =
        let someUtil() = "util code"
    
        member private this.AnotherUtil() = "anotherUtil"
    
        member private this.DoSomething() =
           let anotherA = A()
           A.someUtil()  // compilation failed
           A.AnotherUtil() // ok
    

提交回复
热议问题