Name Tuples/Anonymous Types in F#?

后端 未结 6 1636
执笔经年
执笔经年 2021-02-03 19:46

in C# you can do stuff like :

var a = new {name = \"cow\", sound = \"moooo\", omg = \"wtfbbq\"};

and in

6条回答
  •  被撕碎了的回忆
    2021-02-03 20:36

    As Tony indicated in his answer this is not much better as of F# 4.6. Testing a similar example using .NET Core SDK 3.0.100-preview4-011158 I was able to demonstrate use of the new Anonymous Record feature. As for the RouteMap method, I'm unfamiliar with what types of values this API accepts but I would suspect that the example below would work.

    Ex.

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        {| controller = "Home"; action = "Index"; id = UrlParameter.Optional |} // Parameter defaults
      )
    

    Notice the use of the | character on the insides of the curly braces. This is what now distinguishes regular records from anonymous records in F#.

    As for your other example, perhaps the F# example would now look such as below.

    let a = {| name = "cow"; sound = "moooo"; omg = "wtfbbq" |}
    

提交回复
热议问题