F# collection initializer syntax

后端 未结 6 571
猫巷女王i
猫巷女王i 2021-02-03 19:05

What is the collection initializer syntax in F#? In C# you can write something like:

new Dictionary() {
    {\"One\", 1},
    {\"two\", 2}}
         


        
6条回答
  •  星月不相逢
    2021-02-03 19:39

    To elaborate a bit on collection initialization in F#, here are a few examples:

    read-only dictionary

    dict [ (1, "a"); (2, "b"); (3, "c") ]
    

    seq (IEnumerable)

    seq { 0 .. 99 }
    

    list

    [1; 2; 3; 4; 5]
    

    set

    set [1; 2; 3; 4; 5]
    

    array

    [| 1; 2; 3; 4; 5 |]
    

提交回复
热议问题