Instance creation using var and class c#

Posted by krrishbiju-15589 under C# on 8/6/2013 | Points: 10 | Views : 694 | Status : [Member] | Replies : 2
Hi,

Anyone help me on this,

I have one class
public Class ClassA
{

}

I want to create objects of ClassA

a. ClassA obj=new classA();
b. var obj=new classA();

My doubt is that which one is good a or b?




Responses

Posted by: Bandi on: 8/6/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
I will prefer to use first option..
ClassA obj=new classA();
because sometimes again we need to cast that object reference to respective class in the case of second option

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

krrishbiju-15589, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ssj_Kumar on: 8/12/2013 [Member] Starter | Points: 25

Up
0
Down
ClassA obj=new classA(); will be better, because it will avoid casting work.

Regards,
Jayakumar Selvakani

krrishbiju-15589, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response