简体   繁体   English

在C#中使用F#作为dll

[英]Using F# in C# as dll

Is it possible to use an F# project as an assembly in a C# project? 是否可以将F#项目用作C#项目中的程序集?

If yes; 如是; as F# is faster than C# for calculation stuffs (isn't it?), if the calculation part of the code is in F# and the main project is in C#, does it make the application faster? 因为F#比C#更快用于计算东西(不是吗?),如果代码的计算部分在F#中并且主项目在C#中,它是否会使应用程序更快?

Yes, it's possible to use an F# project as an assembly in a C# project. 是的,可以将F#项目用作C#项目中的程序集。

No, F# is not per se faster than C#. 不,F# 本身并不比C#快。 Both are compiled into the same type of Intermediate Language and run by the same .net Framework. 两者都编译成相同类型的中间语言,并由相同的.net Framework运行。 You might be able to use some specific feature of F# to write a fast algorithm more elegantly than you would in C#, but that depends highly on the algorithm. 您可以使用F#的某些特定功能来编写比C#更优雅的快速算法,但这在很大程度上取决于算法。

  • Yes, F# is a .NET language and will provide a compliant dll 是的,F#是一种.NET语言,它将提供一个兼容的DLL

  • F# is not faster. F#并不快。 F# provides a better way of expressing certain types of problems. F#提供了表达某些类型问题的更好方法。 It therefore reduces amounts of bugs and increases productivity. 因此,它减少了错误数量并提高了生产率。 F# also greatly encourages a programming model that is stateless, more scalable and gives a clear separation of data and functions. F#还极大地鼓励了一种无状态,更具可扩展性的编程模型,并清晰地分离了数据和功能。

Yes, you can and it makes sense. 是的,你可以,这是有道理的。 I personally use that approach in my projects. 我个人在我的项目中使用这种方法。 But the fact that you express a calculation in F# instead of C# doesn't mean that your code will run faster or slower. 但是,您使用F#而不是C#表示计算并不意味着您的代码将运行得更快或更慢。 Of course, if you are familiar with functional programming you'll write faster your calculation code and in a more concise and elegant way, which will also allow you to test, maintain and reason about your code easily. 当然,如果您熟悉函数式编程,您将更快地编写计算代码并以更简洁和优雅的方式编写代码,这样您还可以轻松地测试,维护和推理代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM