在 C# 中,可以像这样定义类型成员常量:
class Foo { public const int Bar = 600; }
IL 看起来像这样。
.field public static literal int32 Bar = int32(600)
我怎样才能在 Visual F#/FSharp 中做同样的事情?
我试过这个无济于事:
[<Sealed>]
type Foo() =
[<Literal>]
let Bar = 600
最佳答案
我不确定这是可能的。事实上,我什至不认为你可以创建不可变的公共(public)字段,更不用说常量了。
关于.net - 如何在 F# 中定义类型成员常量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2399917/