Using extension methods defined in C# from F# code

我的未来我决定 提交于 2019-12-01 03:04:56

Update:

In the current version of F#, you can simply consume extension methods by adding

open TheNamespaceOfExtensionMethod

to your source file (just like you do in C# with a using directive) and simply call the extension method as if it was a normal instance method.

By the way, you can always call them directly just like a normal static method and pass the object reference as the first parameter without any directives if you want. An extension method is simply a static method decorated with ExtensionAttribute under the hood.

Original answer (before F# 2010 beta; not true anymore, as Dykam points out):

I don't think extension methods are supported by F#. You can always call them directly just like a normal static method and pass the object reference as the first parameter.

Brian

Being able to 'import' C#/VB extension methods will be supported in the next release of F#.

See also

F# extension methods in C#

for more detail on the topic.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!