stracture does not containg a user defined default Constracutor why ? [Resolved]

Posted by Harieswer under C# on 8/12/2015 | Points: 10 | Views : 1144 | Status : [Member] | Replies : 1
stracture does not containg a user defined default Constracutor why ?




Responses

Posted by: Rajnilari2015 on: 9/28/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
A struct is a value type and a value type must have a default value as soon as it is declared.

AClass myClassObj;
AStruct myStructObj;

If you declare two fields as above without instantiating either, then break the debugger, myClassObj will be null but myStructObj will not . Given this, a parameter-less constructor would make no sense;
In fact all constructor on a struct has some value assign, we get this just by declaring it.

--
Thanks & Regards,
RNA Team

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

Login to post response