Int data type is value type, then why new int(); [Resolved]

Posted by Allemahesh under C# on 8/19/2013 | Points: 10 | Views : 1028 | Status : [Member] [MVP] | Replies : 2
I know int is value type. But I have not understand why it allow to use new key world.
Example:- int a = new int();
If I use new then it will be reference type. right?
So why int is not reference type in that case.
Also int is class so why it is not reference type?
Can one tell me and make me current?




Responses

Posted by: Ssj_Kumar on: 8/19/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
If I use new then it will be reference type. right?
Answer: not in all case

So why int is not reference type in that case.
Also int is class so why it is not reference type?

Answer: Int is not a class it is struct
ex: public struct Int32(Base case of int)
Can one tell me and make me current?

Always Struct will be value type

I think you cleared




Regards,
Jayakumar Selvakani

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 8/19/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Jayakumar,
Yes I got your answer.
Int is struct and we can create object of struct. struct is value type. So int is value type.
Thank you very munch for clearing my doubts.

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response