简体   繁体   中英

Using an F# library in a C# project in Xamarin

I have a solution in Xamarin Studio with a C# console program trying to call an F# library.

The reference is fine, everything builds.

My F# code looks like the following:

namespace MyStore.Library

module public Lookup =

    open System

    let lookup name (age:int) =
        String.Format("{0}, {1}", name, age.ToString() );

I can call the F# library from an F# console and a C# library from the C# console, but I can't mix the two.

The C# console doesn't see any F# namespaces at all.

What am I doing wrong?

What should I do to see the F# namespace from C#?

In the C# project, you need to add a reference to your F# project.

In the Solution pane, expand your project, and click the gear icon -> Edit References

Then go to Projects tab, check the F# project you want to reference to, then click OK.

编辑参考项目

Also, make sure both C# and F# project target to the same .NET framework! To check that, right click a project, Options -> Build -> General

右键单击项目目标

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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