Hi

I don't think it is anything related to performance. The thing is that in
the first statement you are instantiating the object and sending parameters
to constructor, which may do anything on these parameters apart from copying
the values to object's fields/properties. When you know that certain fields
will always be initialized, you use the constructor with parameters. Also
constructor is part of class/object so it can also initialize the private
fields/properties of the object which the second part cann't do.

Best Regards
SolidRoots


On 3/11/10, Guillermo Zafra <[email protected]> wrote:
>
> Hi all,
>
> Lately I have been researching about how do different methods affect
> performance, and the turn goes to constructors. What i mean is, what's the
> difference (internally) between instantiating and initializing an object
> through the New method and doing it manually?
>
> IE:
>
> Test objTest = new Test(param1, param2);
>
> vs.
>
> Test objTest = new Test();
> objTest.param1 = param1;
> objText.param2 = param2;
>
>
> I know first is more elegant but I'd like to know if the .net framework
> performs different between these two.
>
> Thanks in advance.
>
>
> Guillermo Zafra Prat
> Tlf. 600081625
> [email protected]
> www.nilart.com
> www.gzafra.com
>

Reply via email to