简体   繁体   中英

Accessing an F# Map from inside C# code

Is there any simple way to access an F# Map from inside C# code?

I mean, both C# and F# lists are enumerable so I can iterate an F# list from inside C# code just through that interface, like explained in this post .

Suppose I've declared such a Map inside a F# module called module.fs:

let MyMap : Map<string,T>>

I would like to access the map from inside C# this way:

Map m = module.MyMap;

Is possible to do something like this without performing conversions?

Map is called FSharpMap when accessed outside F#. You could use var to avoid the awkward type name (in your example). However, most F#-specific types implement interfaces that play well across language boundaries. For instance, Map implements IDictionary<_,_> . In APIs that will be used outside F#, the recommended solution is to expose those interfaces instead.

Check out the Component Design Guidelines for more recommendations.

Having said that, you can use FSharpMap from C# without any trouble. It just looks weird and doesn't lend itself to idiomatic C# code.

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