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 type

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

it produces <>f__AnonymousType02 .What does this symbol refer to <>?

+3
source share
2 answers

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

+11
source

This is part of the type name. This does not mean anything specific, but uses a sequence of characters that are unlikely to contradict any human-written code.

+1
source

Source: https://habr.com/ru/post/1725644/


All Articles