简体   繁体   English

C#匿名类型

[英]C# Anonymous Type

When I say Anonymous Type Declaration 当我说匿名类型声明

var someType = new { Name = "Jon Skeet", Age = 10 }; var someType = new {Name =“Jon Skeet”,年龄= 10};

However the Keyword 然而关键字

var is  implicitly typed

but when i print 但是当我打印

Response.Write(someType.GetType().Name);

it produces <>f__AnonymousType0 2 . 它产生<>f__AnonymousType0 2 . What is this symbol <> relates to? 这个符号<>与什么有关?

编译器为您的匿名类型生成一个常规类,并选择一个在IL中有效但在C#中没有的名称,以防止名称与您的类型名称冲突。

It's part of the type name. 它是类型名称的一部分。 It doesn't mean anything specific, but uses a sequence of characters that is unlikely to conflict with any human-written code. 它并不意味着什么具体,但使用一系列不太可能与任何人为编码冲突的字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM