当前位置: 动力学知识库 > 问答 > 编程问答 >

class - How can I delete or create classes at run time c#?

问题描述:

I made a program that achieve a knowledge representation, its good but I thing it could be better if I can create and destroy classes on the fly.

网友答案:

If you are talking about dynamic code generation, here is a link:

dynamic code in c# dynamic code in script

网友答案:

From your description, it sounds like you don't really want to create C# classes at runtime. What you want is some sort of representation of knowledge.

There is no simple answer to this. This is an area of artificial intelligence research. See http://en.wikipedia.org/wiki/Knowledge_representation_and_reasoning for an introduction.

网友答案:

To me it sounds like you want to learn some AI programming and knowledge representation. However this is far different from creating classes at runtime. Wikipedia gives a rather good introduction into the subject, but no code at all.

http://en.wikipedia.org/wiki/Artificial_intelligence

网友答案:

In C# 3.0 it's possible to create anonymous types, though as STW points out, this is not defined at runtime, but compile time.

var myClass = new { A = 5, Id = "MyClass", num = 0.187f};

Console.WriteLine(myClass.Id);

If you're looking to actually create a new class type on the fly, a round-about way is to generate C# class files, compile them into an assembly, and use Reflection to load the classes.

分享给朋友:
您可能感兴趣的文章:
随机阅读: