Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Anonymous Type

When I say Anonymous Type Declaration

var someType = new { Name = "Jon Skeet", Age = 10 };

However the Keyword

var is  implicitly typed

but when i print

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

it produces <>f__AnonymousType02.What is this symbol <> relates to?

like image 674
Russel Avatar asked Jun 25 '26 23:06

Russel


1 Answers

The compiler generates a regular class for your anonymous type and chooses a name that is valid in IL but not in C# to prevent name conflicts with your type names.

like image 130
Daniel Brückner Avatar answered Jun 27 '26 11:06

Daniel Brückner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!