How to use a C# file(.cs file with C# classes) in an F# project

I read C# and F# are interoperable, but when I added a .cs file to an F# console project(in visual studio) the main program file didn’t recognize it.


F# and C# are interoperable on a project level. That is, a C# project can depend on an F# project and vice versa, but each project has to be either in F# or C#.

I think this article explained the interoperability between C# and F# well! :slight_smile:

1 Like

please don’t send me article links, I am looking for an answer not a brochure to read.

I don’t think F# even supports polymorphism nor is it interoperable.

Did you even bother to read my response?

I answered your question. F# and C# are interoperable on a project level. In your screenshot, you have a C# file in an F# project, this will not work. To call your C# code, put it in a separate library project and have the F# project depend on the C# project.

If you are not going to actually read the responses people provide for you and give snarky replies, don’t bother posting anything at all.

1 Like

Kotlin and Java are interoperable.
F# isn’t interoperable with nor C#.
F# doesn’t even have polymorphism.

a proper answer is a step by step walkthrough, not verbose SEOmaxed article links.

F# and other .NET languages are interoperable. Files in a F# project file require strict declaration order, so it’s ridiculous to combine F# source files and C# source files in a single project, as the latter are mutually recursive. You can use dotnet add reference to reference a C# project in your F# project.

F# is a polymorphic language. F# supports parametric polymorphism(via generics), subtype polymorphism(via classes and interfaces, as in C#) and some ad-hoc polymorphism(SRTP). public abstract class ... is not the only way to do polymorphism.

Microsoft and community bloggers have offer thorough tutorials. Please do not try to understand F# in a C# mindset when you first learn it. Instead, read the document and play with the F# environment step-by-step.

1 Like

How about you show respect to the person that actually tried to help you.


a link to an article isn’t help.

that’s the problem with many forums, people dump verbose links instead of to the point answers, and the people that asked for help are to shy to clarify links are not answers.

There is a “to the point answer”. If you do not understand the answer, for example, if you do not know how projects work in .NET, you can ask a followup question. Like:

“Sorry, I don’t quite understand. Could you explain more in detail how I would go about calling C# code from F#? I’m using Visual Studio”

If you did this, I, and anyone else on the forum, would gladly take the time to help.

But instead of doing this, you instead give snarky replies, and then go on to give completely incorrect statements like:

as if they were facts, when you clearly have no idea what you are talking about.

Please, try not to take out your frustration of not understanding something on other people on the forum. It is not the reponsibility of others to spoon-feed you knowledge using paragraphs of HowToo’s. In the end, you have to take responsibility for your own learning and put in the time to do so. :slight_smile:

screenshotting a false claim that F# is interoperable with C# is meaningless.

F# and C# are not interoperable.
F# does not support polymorphism.

I checked in visual studio.
tried the converted livingrimoire core classes code in F#, and tried with a C# file.

no wonder F# is in underuse.
even holyC performs better than F#.