Russel
Russel

Reputation: 111

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?

Upvotes: 3

Views: 898

Answers (2)

ChrisV
ChrisV

Reputation: 3423

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.

Upvotes: 1

Daniel Br&#252;ckner
Daniel Br&#252;ckner

Reputation: 59635

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.

Upvotes: 12

Related Questions