.net - 如何在 F# 中定义类型成员常量?

标签 .net f# constants

在 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/

相关文章:

C# TCP 套接字性能随着应用程序运行而下降

c# - 仅在发布版本中捕获控制台关闭事件时,.NET 应用程序崩溃

.net - 您将如何在 .NET/SQL Server 中构建这个消息处理系统?

F# 将空引用传递给 ref 参数

f# - Newtonsoft.Json 将某些项目序列化两次

c++ - C/C++ : Optimization of pointers to string constants

ruby - 在 Ruby 中,模块中定义的类如何知道模块的常量?

.NET 代码安全审查工具

c++ - 静态 const 成员的 const_cast

list - F#函数查找列表的所有旋转