F#Static关键词
在F#中,Static是一个关键词。用于制作static字段或static方法。static不是Object的一部分。它有自己的存储空间来存储static数据。它用于在对象之间共享公共属性。
F# Static示例1
type Account(accno,name) = class static let rateOfInterest = 8.8 member this.display()= printfn "%d %s %0.2f" accno name rateOfInterest end let a1 = new Account(101,"Rajkumar") let a2 = new Account(102, "john") a1.display() a2.display()
输出:
101 Rajkumar 8.80 102 john 8.80
F# Static字段示例2
type Account() = class static let mutable count = 0 new(accno,name) = count<-count+1 printfn "%d %s" accno name Account() static member DisplayCount() = printfn "Object Counter = %d" count end let a1 = new Account(101,"Rajkumar") let a2 = new Account(102, "john") Account.DisplayCount()
输出:
101 Rajkumar 102 john Object Counter = 2
祝学习愉快! (发现内容有误?请选中要编辑的内容 -> 右键 -> 修改 -> 提交!帮助我们改进教程质量)
精选教程推荐
👇 以下精选教程可能对您有帮助,拓展您的技术视野
暂无学习笔记,成为第一个分享的人吧!
您的笔记将帮助成千上万的学习者