Class instances differences

Posted by krrishbiju-15589 under C# on 7/25/2013 | Points: 10 | Views : 1420 | Status : [Member] | Replies : 5
Hi ,
I have class ClassA.
What is the difference between
ClassA ob=new ClassA(); and
ClassA ob=null;


Thanks and Regards
krrish




Responses

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

Up
0
Down
Adding some more interesting points
Class1 MyClass=new Class1();
Memory will be created in Heap
This is reference type

Class1 MyClass=null;
Memory will be created in Stack
This is Value type

Regards,
Jayakumar Selvakani

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

Posted by: krrishbiju-15589 on: 7/25/2013 [Member] Starter | Points: 25

Up
0
Down
Interesting....can you pleases explain when and why these two used.....
Thanks
krrish

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

Posted by: Ssj_Kumar on: 7/27/2013 [Member] Starter | Points: 25

Up
0
Down
Have a look on below link, it may explain some extend
http://forums.asp.net/t/1906391.aspx/1?difference+between+class+variable+and+class+object+c+

Regards,
Jayakumar Selvakani

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

Posted by: aswinialuri-19361 on: 7/30/2013 [Member] Starter | Points: 25

Up
0
Down
hi,
ClassA ob=new ClassA(); it creates new instance and default constructor
ClassA ob=null; it is null reference and it doesn't create any constructor.

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

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

Posted by: Ssj_Kumar on: 7/31/2013 [Member] Starter | Points: 25

Up
0
Down
Class1 MyClass=new Class()
Object will be created in Heap and address will be saved in Stack, In this case we are using both Heap and StacK
In this case this is reference type

Class1 MyClass=null;
Object will not be created so it won't create your Heap, Only Stack memory will be created and it hold Null Value
In this case this is Value type

Regards,
Jayakumar Selvakani

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

Login to post response