3

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?

2
  • 6
    Though the type logically does not have a name, the metadata format does not permit nameless types, so we just pick an "impossible" name. You'll note that we do the same thing for anonymous functions. If you're clever, you can get the method info for an anonymous function and ask its name; you'll get a similar "impossible" name back. We also generate impossible names for closures, special fields of iterator blocks, and so on. Commented Dec 14, 2009 at 18:53
  • I hope you are in compiler development team @ Microsoft.Right ? Commented Dec 14, 2009 at 19:04

2 Answers 2

12

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.