C# 7.0 ValueTuples vs Anonymous Types(C# 7.0 ValueTuples 与匿名类型)
问题描述
看看新的 C# 7.0 ValueTuples,我想知道它们是否会完全取代 Anonymous Types.我知道 ValueTuples 是结构,因此其行为与作为类的 Anonymous Types 有点不同.但是,我没有看到使用 Anonymous Type 而不是 ValueTuple 的用例.
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.
是否存在使用 匿名类型 仍然比在 C# 7.0 中使用 ValueTuples 有益的用例?
Are there any use-cases where using an Anonymous Type would still be beneficial over using ValueTuples in C# 7.0?
推荐答案
匿名类型是不可变的,ValueTuple 不是.这反映在匿名类型公开属性,ValueTuple 公开字段的事实中.数据绑定几乎总是需要属性.
Anonymous types are immutable, ValueTuples are not. This is reflected in the fact that anonymous types expose properties, ValueTuples expose fields. Data binding almost always requires properties.
大量现有代码仅适用于引用类型,不适用于值类型.特别想到的是 Entity Framework 中的预测:对值类型的预测根本没有实现.
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.
这篇关于C# 7.0 ValueTuples 与匿名类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# 7.0 ValueTuples 与匿名类型
基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
