if Value Types and Reference Type are from Object Type which is a reference type, then how value type is value type and reference type is reference when they all come from refernce type.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Basically, it is a cheat ;-p
Any
struct(i.e. anything inherited fromValueType) is treated with value-type semantics. But there is a boxing conversion toobjectas necessary; meaning that if you cast astructto anobject, it will create a special object (on the managed heap) containing the data (as a clone) from your value*.The boxed version is a reference-type. You can unbox this (by casting) back to the
structversion, which reverses this (copies the clones data from the object on the heap into your local value).*=unless it is an empty
Nullable<T>, which boxes tonull; likewise,nullunboxes to an emptyNullable<T>.