Looking at the new C# 7.0 ValueTuples, I am wondering if they will completely replace Anonymous Types
. I understand that ValueTuples
are structs and therefore behave a bit differently than Anonymous Types
which are classes. I don't see a use-case, however, in which I would prefer using an Anonymous Type
over a ValueTuple
.
Are there any use-cases where using an Anonymous Type
would still be beneficial over using ValueTuples
in C# 7.0?
Anonymous types are immutable, ValueTuple
s are not. This is reflected in the fact that anonymous types expose properties, ValueTuple
s expose fields. Data binding almost always requires properties.
Plenty of existing code only works with reference types, not with value types. What in particular comes to mind are projections in Entity Framework: projections to value types are simply not implemented.