Anonymous type and tuple

后端 未结 4 1427
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-25 12:09

What is the difference between anonymous type and tuple?

4条回答
  •  醉话见心
    2020-12-25 12:38

    Another point in favor of anonymous types would be that you can easily have more than 8 properties. While this is doable using tuples, it's not so pretty.

    var tuple = Tuple.Create(1, 2, 3, 4, 5, 6, 7, Tuple.Create(8, 9)); //and so on
    

    or write your own tuple classes.


    An interesting similarity to note is that both tuples and anonymous types give you immutability and equality comparability (both overrides Equals and GetHashCode) based on the properties by default.

提交回复
热议问题