{"id":72,"date":"2014-08-01T12:28:44","date_gmt":"2014-08-01T12:28:44","guid":{"rendered":"http:\/\/mairwa.com\/wordpress\/?p=72"},"modified":"2014-08-01T12:28:44","modified_gmt":"2014-08-01T12:28:44","slug":"value-types-and-reference-types-comparison","status":"publish","type":"post","link":"http:\/\/mairwa.com\/wordpress\/?p=72","title":{"rendered":"Value Types and Reference Types Comparison"},"content":{"rendered":"<table width=\"583\" border=\"2\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"168\"><b>Intriguing Question<\/b><\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"180\"><b>Value Type<\/b><\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"235\"><b>Reference Type<\/b><\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"168\"><b>How is a variable represented?<\/b><\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"180\"><b>Value type variables are local copies.<\/b><\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"235\"><b>Reference type variables are pointing to the memory occupied by the allocated instance.<\/b><\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"168\"><b>What is the base type?<\/b><\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"180\"><b>Implicitly extends System.ValueType.<\/b><\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"235\"><b>Can derive from any other type (except System. ValueType), as long as that type is not \u201csealed\u201d (more details on this in Chapter 6).<\/b><\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"168\"><b>Can this type function as a base to other types?<\/b><\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"180\"><b>No. Value types are always sealed and cannot be inherited from.<\/b><\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"235\"><b>Yes. If the type is not sealed, it may function as a base to other types.<\/b><\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"168\"><b>What is the default parameter passing behavior?<\/b><\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"180\"><b>Variables are passed by value (i.e., a copy of the variable is passed into the called function).<\/b><\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"235\"><b>For value types, the object is copied-by-value. For reference types, the reference is copied-by-value.<\/b><\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"168\"><b>Can this type override System.Object.Finalize()?<\/b><\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"180\"><b>No. Value types are never placed onto the heap and, therefore, do not need to be finalized.<\/b><\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"235\"><b>Yes, indirectly (more details on this in Chapter 13).<\/b><\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"168\"><b>Can I define constructors for this type?<\/b><\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"180\"><b>Yes, but the default constructor is reserved (i.e., your custom constructors must all have arguments). <\/b><\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"235\"><b>But, of course!<\/b><\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"168\"><b>When do variables of this type die?<\/b><\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"180\"><b>When they fall out of the defining scope.<\/b><\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"235\"><b>When the object is garbage collected.<\/b><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">Intriguing Question Value Type Reference Type How is a variable represented? Value type variables are local copies. Reference type variables are pointing to the memory occupied by the allocated instance. What is the base type? Implicitly extends System.ValueType. Can derive from any other type (except System. ValueType), as long as that type is not \u201csealed\u201d (more details on this in&hellip; <a href=\"http:\/\/mairwa.com\/wordpress\/?p=72\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-72","post","type-post","status-publish","format-standard","hentry","category-c-vb","xfolkentry"],"_links":{"self":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/72","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=72"}],"version-history":[{"count":0,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/72\/revisions"}],"wp:attachment":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}