Question

What's the difference between normal types and anonymous types in C#, regarding to compilation process and memory management at runtime? Are anonymous types more inneficient in some way than normal types?

Was it helpful?

Solution 2

What's the difference between normal types and anonymous types in C# regarding memory management at runtime? Are anonymous types more inefficient in some way than normal types?

Anonymous types are neither more nor less than generic internal classes with a constructor, readonly fields, and an implementation of GetHashCode and ToString. There's nothing special about them as far as the runtime is concerned. The runtime does not know that they are "anonymous"; the runtime sees them as just another class. The generated code is nothing interesting.

What's the difference between normal types and anonymous types in C#, regarding to compilation process?

I have no idea what this question means to ask.

OTHER TIPS

From MSDN:-

Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to first explicitly define a type. The type name is generated by the compiler and is not available at the source code level. The type of the properties is inferred by the compiler.

Remarks:

Anonymous types are reference types that derive directly from object. The compiler gives them a name although your application cannot access it. From the perspective of the common language runtime, an anonymous type is no different from any other reference type, except that it cannot be cast to any type except for object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top