Converting between C# List and F# List

前端 未结 1 1580
遇见更好的自我
遇见更好的自我 2021-01-02 04:40

Remark: This is a self-documentation, but if you have any other suggestions, or if I made any mistakes/miss out something obvious, I would really appreciate your help.

相关标签:
1条回答
  • 2021-01-02 05:21

    Inside a C# document, I can use ListModule.OfSeq and .ToList(), like this:

    // Currently inside a C# document
    var CS_list = new List<int> {1,2,3}; 
    var FS_list = ListModule.OfSeq(CS_List); // Microsoft.FSharp.Collections.ListModule
    var CS_converted_back = FS_List.ToList();
    

    Inside an F# document, I can use Seq.toList and ResizeArray<_>, like this:

    // Currently inside an F# document
    let FS_list = [1;2;3]
    let CS_list = ResizeArray<int> FS_list // System.Collections.Generic.List
    let FS_converted_back = Seq.toList CS_list
    

    If I made any mistakes, or if I miss out something obvious, please let me know.

    0 讨论(0)
提交回复
热议问题