ske*_*ker 27
当然,只需在方法前加上static关键字.这是一个例子:
type Example = class
static member Add a b = a + b
end
Example.Add 1 2
val it : int = 3
Run Code Online (Sandbox Code Playgroud)
如果您想在静态类中使用静态方法,请使用Module
查看此链接,特别是模块部分:
http://fsharpforfunandprofit.com/posts/organizing-functions/
这是一个包含两个函数的模块:
module MathStuff =
let add x y = x + y
let subtract x y = x - y
Run Code Online (Sandbox Code Playgroud)
在幕后,F#编译器使用静态方法创建一个静态类.所以C#等价物将是:
static class MathStuff
{
static public int add(int x, int y)
{
return x + y;
}
static public int subtract(int x, int y)
{
return x - y;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6828 次 |
| 最近记录: |