Alex Rivera | Logout

Can I specify a meaningful name for an anonymous class in C#?

Asked 2009-04-27T13:08:48.847
44

We all know that when we create an anonymous class like this:

var Employee = new { ID = 5, Name= "Prashant" };

...at run time it will be of type:

<>f__AnonymousType0<int,string>

Is there any way to specify a meaningful name to such classes?

Edit
Report

2 Answers

4

Yes, you are creating an Anonymous Class , if you want your class to have a name, i.e. Not Anonymous, then declare a regular class or struct.

answered 2009-04-27T13:15:49.390
2

I think that, by definition, Anonymous Types can't have a name, just that which the compiler gives it. If you're looking for more meaningful design-time information on Anonymous Types then you're expecting too much from the compiler.

answered 2009-04-27T13:14:00.410

Your Answer