Concisely creating an IDictionary<_,obj>

后端 未结 7 1510
萌比男神i
萌比男神i 2020-12-03 23:09

Is there a shorter way of creating an IDictionary<_,obj>, possibly without boxing every value? This is what I have.

let values =
  [ \"a\"         


        
7条回答
  •  温柔的废话
    2020-12-04 00:10

    Here's a solution, following kvb's suggestion (probably the most concise, and clearest, so far):

    let inline (=>) a b = a, box b
    
    let values =
      [ "a" => 1
        "b" => "foo"
        "c" => true ]
      |> dict
    

提交回复
热议问题