Tekkaman

导航

 

C#匿名类型 - Anonymous Types

  Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first. The type name is generated by the compiler and is not available at the source code level. The type of each property is inferred by the compiler.

  匿名类型属性为只读,被编译器生成,每个属性被编译器推断生成。

  

  匿名类型最常用场景为,当一个类数据过大,而我们只想抽取其中几个属性来使用时。例如:

  

  也可以生成匿名类型数组:

  

参考:http://msdn.microsoft.com/zh-cn/library/bb397696.aspx

posted on 2014-07-17 09:37  Tekkaman  阅读(657)  评论(0编辑  收藏  举报