每个属性的类型由编译器推断。
对象和集合初始值设定项(C# 编程指南)。
Message 的属性进行初始化的匿名类型。
var v = new { Amount = 108, Message = "Hello" };
// Rest the mouse pointer over v.Amount and v.Message in the following
// statement to verify that their inferred types are int and string.
Console.WriteLine(v.Amount + v.Message);
LINQ 查询表达式(C# 编程指南)。
null、匿名函数或指针类型。
这将导致在查询中返回较少数量的数据。
Price。
var productQuery =
from prod in products
select new { prod.Color, prod.Price };
foreach (var v in productQuery)
{
Console.WriteLine("Color={0}, Price={1}", v.Color, v.Price);
}
隐式类型的局部变量(C# 编程指南)。
可通过将隐式键入的本地变量与隐式键入的数组相结合创建匿名键入的元素的数组,如下面的示例所示。
var anonArray = new[] { new { name = "apple", diam = 4 }, new { name = "grape", diam = 1 }};