Is it possible to override the new() function?
>
like in TestObject to = new TestObject();
>
thnx,
Henk
You can add a parametersless public constructor to the class, but I'm not
sure this is what you want. You cannot, as in C++, override the new function.
public class TestObject
{
public TestObject()
{
// your stuff here
}
}
Your question is not so clear, in fact there is not need for these, Why, its
all about patterns, means the new just create an instance of your class, that
all, but the only things you can do is just change the creation mode, for
example, do i want common object or singletone object or static objec, maybe
i need a factory.
So, new just define the pattern which the object create.
--
Sincerely
Yaron Karni
Is it possible to override the new() function?
>
like in TestObject to = new TestObject();
>
thnx,
Henk
>
>
I guess not. In C++ one overrides new operator for example to allocate
objects from somewhere else than heap (to build GC or something). Since
..NET allocates objects, you should let it do its work. However, you
might succeed in refractoring the constructor calls using Reflection.Emit .
Comment