Creating a dynamic anonymous types variables

巧了我就是萌 提交于 2019-12-04 12:32:33

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.

No, you cant.

2nd question: No such thing, it might refer to compiler generated class which you have no access to.

No, and It would not be efficient for Your application. Are You convinced that You don't want to introduce some kind of class?

using System;
class Generic{

   public void doSomething(){}

   private string name;
   private string _othreFeature;

}

You could extend it with new features, whenever You want.

Joshua

This is a perfectly logical question... I work with Java and C# both and this is a big pet peeve of mine... Matter of fact almost every language out there has some sort of Anonymous type lol... PHP, JavaScript, C#, vb (all), and the list goes on..

It's a very useful feature to have when you're basically throwing data into an object and you don't need a class for it created.

Matter of fact this is exactly what LINQ utilizes..

var someObject (can be interable/Enumerable) = 
    from p in products
    where p.id == 123
    select new { productid };

blah blah you get the idea.. It's very useful... :-)

Cheers!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!