Name Tuples/Anonymous Types in F#?

后端 未结 6 1637
执笔经年
执笔经年 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:46

    Now in F# 4.6 (preview) we have Anonymous Records

    So we can have this code syntax:

    let AwesomeAnonymous = {|  ID = Guid.NewGuid()
                               Name = "F#"
                            |}
    
    AwesomeAnonymous.Name |> Debug.WriteLine
    

    It is also supported on the Visual Studio Intellisense:

    So that code could be like this:

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

    See also: Announcing F# 4.6 Preview

提交回复
热议问题