我可以创建一个对象而不使用“新”对象关键词? [英] can i create an object without using "new" keyword?

查看:72
本文介绍了我可以创建一个对象而不使用“新”对象关键词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建对象而不使用new关键字....如果有任何解决方案,请帮助我。

i want to create object without using "new" keyword....if there is any solution ,plz help me.

推荐答案

嗯,是的 - 你可以使用 Assembly.CreateInstance( [ ^ ]方法 - 但它只适用于特殊情况。如果可以的话,使用 new 会更容易,更容易理解。



另一种方法是将对象创建为 struct 而不是 class - 但如果您不完全了解其中的差异,则会引入许多新问题。 MSDN:使用结构 [ ^ ]
Well, yes - you can use the Assembly.CreateInstance([^] method - but it's only really of use in specialised circumstances. Using new is a lot easier and easier to follow if you can.

The other alternative is to create your objects as struct rather than class - but that introduces a lot of new problems if you don't fully understand the difference. MSDN: Using Structs[^]


对象工厂提供了另一种创建对象的方法(例如,参见\"C# Factory Pattern [ ^ ]但是,在内部,工厂必须使用 new
Object factories provide an alternative way for creating the objects (see, for instance, "C# Factory Pattern"[^]), however, internally, a factory has to use new.


这篇关于我可以创建一个对象而不使用“新”对象关键词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆