Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a dynamic anonymous types variables

Can I create an anonymous type variable and later on add more Properties?

E.g. var x = new { Name = "Ahmed" }; and want to add Age to it? how can I do this?

Another question: i saw on some blogs a type AnonymousType what is the name space for this class? here is am example http://www.codeproject.com/KB/cs/AnonymousTypesInCSharp.aspx

like image 352
Ahmed Magdy Avatar asked Feb 05 '26 13:02

Ahmed Magdy


1 Answers

First question - you can't.

Second question - AnonymousType is the type the author of that article created. You have to download the source for his project to use that type.

like image 144
Justin Niessner Avatar answered Feb 07 '26 03:02

Justin Niessner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!