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

后端 未结 5 376
花落未央
花落未央 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:42

    For 2-tuples, you can still always use the KeyValuePair from earlier versions of the Common Type System. It's a value type.

    A minor clarification to the Matt Ellis article would be that the difference in use semantics between reference and value types is only "slight" when immutability is in effect (which, of course, would be the case here). Nevertheless, I think it would have been best in the BCL design not to introduce the confusion of having Tuple cross over to a reference type at some threshold.

提交回复
热议问题