在C#中,有什么区别
static readonly string MyStr;
Run Code Online (Sandbox Code Playgroud)
和
const string MyStr;
Run Code Online (Sandbox Code Playgroud) 我有以下C#代码.
namespace MyMath {
public class Arith {
public Arith() {}
public int Add(int x, int y) {
return x + y;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想出了名为testcs.fs的F#代码来使用这个对象.
open MyMath.Arith
let x = Add(10,20)
Run Code Online (Sandbox Code Playgroud)
当我运行以下命令
fsc -r:MyMath.dll testcs.fs
我收到此错误消息.
/Users/smcho/Desktop/cs/namespace/testcs.fs(1,13): error FS0039: The namespace 'Arith' is not defined /Users/smcho/Desktop/cs/namespace/testcs.fs(3,9): error FS0039: The value or constructor 'Add' is not defined
可能有什么问题?我在.NET环境中使用mono.
这个问题很相似,但我没有看到令我满意的答案。
那么,等效项public static readonly string Name = ...;在 F# 中看起来如何?
我可以定义static member Name = ...,但这会创建静态只读属性。