📅  最后修改于: 2021-01-01 14:32:39             🧑  作者: Mango
在F#中,static是关键字。它用于制作静态字段或静态方法。静态不是对象的一部分。它具有自己的内存空间来存储静态数据。它用于在对象之间共享通用属性。
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
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