我们为何不喜欢清单4中的匿名类型?
基于以下几个原因,应该避免使用匿名类型。
讨论匿名类型结构比讨论命名类型结构更加困难。
Structures of anonymous types are more difficult to discuss than structures of named types.
因此,如果您可以自由修改架构,最好避免匿名类型。
So if you have the freedom to modify the schemas, it is best to avoid anonymous types.
对于局部元素或匿名类型,目前不能使用可重用映射。
In the case of local elements or anonymous types, reusable mappings are not an option at this time.
可以通过将匿名类型转换为命名类型来解决这些问题。
These issues can be remedied by converting anonymous types to named types.
submap细化不可用于处理局部元素或匿名类型。
The Submap refinement is not available when working with local elements or anonymous types.
匿名类型必须用对象初始值设定项加以声明。
Anonymous types must be declared with an object initializer.
使用类型引用和匿名类型的结构子类型转化(动态类型)。
Structural Subtyping (duck typing) using type inference and anonymous types.
按照以下步骤,将清单1中的匿名类型转换为清单2中的命名类型。
We followed these steps to transform listing 1's anonymous type into listing 2's named type.
本文将总结使用匿名类型可能会引起的问题,希望读者能够避免它们。
This article codifies issues that may arise from using anonymous types in hopes that readers will avoid them.
VB和C#之所以能不同的实现方式是因为匿名类型是一个编译器特性。
The reason VB and C# can use different implementations is that anonymous types are a compiler feature.
JAXB非常稳健,可允许您通过绑定文件来命名需要命名的匿名类型。
JAXB is robust enough to allow you to name anonymous types as you need to via the binding file.
匿名类型的名称由编译器生成,并可能随编译的不同而不同。
The name of the anonymous type is compiler generated, and it may vary from compilation to compilation.
当创建匿名类型时,程序员可以用关键词“Key”表示哪些字段是稳定的。
When creating anonymous classes, programmers can use the modifier "Key" to indicate which fields are immutable.
在清单8的例子中,我们定义了一个匿名类型,没有明确地命名这个复杂类型。
In the example in Listing 8, we have defined what is called an anonymous type, where no explicit name is given to the complex type.
CLR自己对匿名类型没有什么概念,只是把它们看作有着自动产生名字的普通类。
The CLR itself doesn't have any notion of anonymous types and sees them as normal classes with automatically generated names.
有同样属性名和类型的两个匿名类型对象将被指派为自动生成的同样的类。
Two anonymously typed objects that have the same property names and types will be assigned to the same automatically generated class.
请注意,在此特定示例中,最终的输出不是组,而是匿名类型的平面序列。
Note that in this particular example the final output is not a group, but a flat sequence of anonymous types.
代码不应使用或依赖匿名类型的名称,因为重新编译项目时该名称可能更改。
Your code should not use or rely on the name of an anonymous type because the name might change when a project is recompiled.
但我们认为,匿名类型没有命名类型那样的可读性;深层嵌套的XML结构通常难以理解。
But in our opinion, anonymous types aren't as readable as named types; a deeply nested XML structure is almost always more difficult to understand readily.
类型推断—使用匿名类型时,关键字var必不可少。它还能减少你其他变量声明中的冗余。
Type Inference - the var keyword, which is necessary when using anonymous types, can also reduce redundancy in your other variable declarations.
此架构的作者在构建这类架构时也不太可能会意识到匿名类型可能会导致潜在问题。
It is unlikely that the authors of such schemas realize the potential problems that they may cause when they build such schemas.
提供有关如何将LINQ查询的结果作为特定类型而非匿名类型返回的示例。
Provides an example of how to return the results of a LINQ query as a specific type instead of as an anonymous type.
查询表达式经常使用匿名类型,而这些类型只能使用对象初始值设定项进行初始化。
Query expressions make frequent use of anonymous types, which can only be initialized with an object initializer.
匿名类型允许您定义一个类,然后在不给出类名称的情况下声明并初始化该类的对象。
Anonymous types allow you to define a class, then declare and initialize an object of that class, without giving the class a name.
而VB却同时支持可变和不可变的匿名类型,对于这两种匿名类型,实现和使用的规则也略有不同。
VB allows both mutable and immutable anonymous types, with subtly different rules for each.
由于命名类型和匿名类型的不同,qnamescope属性将影响到定制绑定如何与运行时系统交互。
The qnameScope property affects how the custom binder interacts with the run time system because of differences between the named types and the anonymous types.
用于声明匿名类型实例的格式类似于在使用对象初始值设定项声明命名类型实例时使用的格式。
The format you use to declare an instance of an anonymous type resembles the format you use when you declare an instance of a named type by using an object initializer.
为了支持类似哈希表的数据结构和像分组这样的查询操作,由LINQ创建的匿名类型必须提供稳定的哈希码。
In order to support data structures like hash tables and query operations like grouping, anonymous types created by LINQ must provide stable hash codes.
应用推荐