Why is the new Tuple type in .Net 4.0 a reference type (class) and not a value type (struct)

后端 未结 5 380
花落未央
花落未央 2020-12-07 18:03

Does anyone know the answer and/or have an opinion about this?

Since tuples would normally not be very large, I would assume it would make more sense to use structs

5条回答
  •  伪装坚强ぢ
    2020-12-07 18:58

    I don't know but if you have ever used F# Tuples are part of the language. If I made a .dll and returned a type of Tuples it be nice to have a type to put that in. I suspect now that F# is part of the language (.Net 4) some modifications to CLR were made to accommodate some common structures in F#

    From http://en.wikibooks.org/wiki/F_Sharp_Programming/Tuples_and_Records

    let scalarMultiply (s : float) (a, b, c) = (a * s, b * s, c * s);;
    
    val scalarMultiply : float -> float * float * float -> float * float * float
    
    scalarMultiply 5.0 (6.0, 10.0, 20.0);;
    val it : float * float * float = (30.0, 50.0, 100.0)
    

提交回复
热议问题