【发布时间】:2009-11-03 11:52:30
【问题描述】:
我正在研究 F#,它非常吸引人。我正在尝试将可选类型和 C# 结合起来,例如 here。很有趣的事情......但是我想念一些重要的事情:
#light
namespace MyFSharp
// C# way
[<System.Runtime.CompilerServices.Extension>]
module ExtensionMethods =
[<System.Runtime.CompilerServices.Extension>]
let Great(s : System.String) = "Great"
using System;
using MyFSharp; // reference the F# dll
class Program
{
static void Main(string[] args)
{
var s = "foo";
//s.Awesome(); // no
Console.WriteLine(s.Great()); // yes
}
}
这很简单——我想这对我来说还为时过早……我明白了:
The type 'Extension' is not defined
也许为时过早...但我就是不明白为什么找不到它。
谢谢, 马吕斯
【问题讨论】:
-
您应该在两个不同的 pre 块中显示 F# 和 C# 代码。我的意思是说使用 System; 在上面的普通文本中添加一个“C#:”;以避免混淆。乍一看,您似乎正在尝试在 F# 中使用类/Main 方法。
标签: c# f# extension-methods