°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡are¡¡displayed¡¡again¡¡to¡¡show¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡which¡¡variable¡¡has¡¡been¡¡modified¡¡
Figure¡¡4¡5¡£¡¡¡¡Using¡¡a¡¡custom¡¡value¡¡type¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡As¡¡a¡¡parison£»¡¡the¡¡same¡¡operations¡¡can¡¡be¡¡carried¡¡out¡¡using¡¡a¡¡reference¡¡type£»¡¡where¡¡the¡¡¡¡
reference¡¡code¡¡is¡¡as¡¡follows£º¡¡
Dim¡¡val¡¡As¡¡MyReferenceType¡¡=¡¡New¡¡MyReferenceType£¨£©¡¡
Dim¡¡copiedVal¡¡As¡¡MyReferenceType¡¡=¡¡val¡¡
Console¡£WriteLine£¨¡¨val¡¡value=¡¨¡¡&¡¡val¡£value¡¡&¡¡_¡¡
¡¡¡¡¡¡¡¡¡¨¡¡copiedVal¡¡value=¡¨¡¡&¡¡copiedVal¡£value£©¡¡
val¡£value¡¡=¡¡10¡¡
Console¡£WriteLine£¨¡¨val¡¡value=¡¨¡¡&¡¡val¡£value¡¡&¡¡_¡¡
¡¡¡¡¡¡¡¡¡¨¡¡copiedVal¡¡value=¡¨¡¡&¡¡copiedVal¡£value£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡So£»¡¡if¡¡two¡¡code¡¡pieces¡¡are¡¡functionally¡¡identical£»¡¡with¡¡the¡¡single¡¡difference¡¡being¡¡their¡¡type¡¡¡¡
£¨value¡¡type¡¡versus¡¡reference¡¡type£©£»¡¡will¡¡they¡¡generate¡¡the¡¡same¡¡results£¿¡¡
¡¡¡¡¡¡¡¡¡¡¡¡Running¡¡both¡¡code¡¡pieces¡¡results¡¡in¡¡the¡¡following¡¡output£º¡¡
var¡¡value=0¡¡copiedVar¡¡value=0¡¡
var¡¡value=10¡¡copiedVar¡¡value=0¡¡
val¡¡value=0¡¡copiedVal¡¡value=0¡¡
val¡¡value=10¡¡copiedVal¡¡value=10¡¡
¡¡¡¡¡¡¡¡¡¡¡¡Looking¡¡closely¡¡at¡¡the¡¡results£»¡¡you¡¡see¡¡that¡¡two¡¡functionally¡¡identical¡¡code¡¡pieces¡¡that¡¡differ¡¡¡¡
only¡¡in¡¡the¡¡variable¡¡type¡¡they¡¡use¡¡generate¡¡pletely¡¡different¡¡results£º¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡106¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
84¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡4¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡D¡¡AT¡¡A¡¡¡¡S¡¡TR¡¡U¡¡CT¡¡U¡¡R¡¡E¡¡S£»¡¡¡¡¡¡DE¡¡CI¡¡SI¡¡ON¡¡S£»¡¡¡¡¡¡A¡¡N¡¡D¡¡¡¡¡¡L¡¡O¡¡OP¡¡S¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡When¡¡you¡¡assign¡¡and¡¡modify¡¡a¡¡value¡¡type£»¡¡only¡¡the¡¡contents¡¡of¡¡the¡¡modified¡¡variable¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡change¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡When¡¡you¡¡assign¡¡and¡¡modify¡¡a¡¡reference¡¡type£»¡¡the¡¡original¡¡object¡¡changes£»¡¡so¡¡the¡¡original¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡variable¡¡and¡¡assigned¡¡variable¡¡change¡¡because¡¡they¡¡both¡¡point¡¡to¡¡the¡¡same¡¡original¡¡object¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡example¡¡demonstrates¡¡that¡¡when¡¡defining¡¡user¡defined¡¡types£»¡¡you¡¡need¡¡to¡¡be¡¡careful¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡how¡¡you¡¡treat¡¡value¡¡and¡¡reference¡¡types¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡As¡¡you¡¡learned¡¡in¡¡Chapter¡¡2£»¡¡a¡¡value¡¡type¡¡is¡¡stored¡¡on¡¡the¡¡stack¡£¡¡Thus£»¡¡declaring¡¡a¡¡user
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡defined¡¡value¡¡type¡¡means¡¡the¡¡full¡¡contents¡¡of¡¡the¡¡user¡defined¡¡type¡¡are¡¡stored¡¡on¡¡the¡¡stack£»¡¡and¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡when¡¡you¡¡assign¡¡one¡¡value¡¡type¡¡variable¡¡to¡¡another¡¡value¡¡type¡¡variable£»¡¡you¡¡are¡¡copying¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡plete¡¡contents¡¡of¡¡the¡¡value¡¡type¡£¡¡This¡¡copying¡¡was¡¡obvious¡¡in¡¡our¡¡example¡¡when¡¡we¡¡used¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡simple¡¡numeric¡¡number¡¡types¡¡£¨such¡¡as¡¡Double£©£»¡¡but¡¡when¡¡you¡¡copy¡¡plete¡¡structures¡¡with¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡contents£»¡¡the¡¡side¡¡effects¡¡might¡¡not¡¡be¡¡what¡¡you¡¡expect¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Value¡¡Types¡¡That¡¡Contain¡¡Reference¡¡Types¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Value¡¡types¡¡copy¡¡the¡¡contents¡¡when¡¡you¡¡assign¡¡variables£»¡¡but¡¡there¡¡is¡¡caveat¡¡in¡¡that¡¡this¡¡rule¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡does¡¡not¡¡apply¡¡if¡¡the¡¡value¡¡type¡¡contains¡¡a¡¡reference¡¡type¡£¡¡Consider¡¡the¡¡following¡¡declaration¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Structure¡¡MyValueTypeWithReferenceType¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡value¡¡As¡¡Integer¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡reference¡¡As¡¡MyReferenceType¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Structure¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡first¡¡line¡¡in¡¡the¡¡value¡¡type¡¡declaration¡¡contains¡¡a¡¡single¡¡value¡¡type¡¡£¨Integer£©¡£¡¡The¡¡second¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡line¡¡is¡¡the¡¡data¡¡member¡¡declaration¡¡that¡¡is¡¡a¡¡reference¡¡type¡£¡¡The¡¡declaration¡¡implies¡¡that¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡value¡¡type¡¡is¡¡stored¡¡on¡¡the¡¡stack£»¡¡but¡¡the¡¡reference¡¡type¡¡is¡¡on¡¡the¡¡heap¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡value¡¡type¡¡that¡¡contains¡¡a¡¡reference¡¡type¡¡is¡¡manipulated¡¡using¡¡the¡¡following¡¡test¡¡code¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡var¡¡As¡¡MyValueTypeWithReferenceType¡¡=¡¡New¡¡MyValueTypeWithReferenceType£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡var¡£reference¡¡=¡¡New¡¡MyReferenceType£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡copiedVar¡¡As¡¡MyValueTypeWithReferenceType¡¡=¡¡var¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨var¡¡value=¡¨¡¡&¡¡var¡£reference¡£value¡¡&¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¨¡¡copiedVar¡¡value=¡¨¡¡&¡¡copiedVar¡£reference¡£value£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡var¡£reference¡£value¡¡=¡¡10¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨var¡¡value=¡¨¡¡&¡¡var¡£reference¡£value¡¡&¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¨¡¡copiedVar¡¡value=¡¨¡¡&¡¡copiedVar¡£reference¡£value£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡It¡¡is¡¡important¡¡to¡¡realize¡¡that¡¡allocating¡¡MyValueTypeWithReferenceType¡¡does¡¡not¡¡imply¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡an¡¡allocation¡¡of¡¡the¡¡embedded¡¡custom¡¡type¡£¡¡In¡¡the¡¡test¡¡code£»¡¡the¡¡allocation¡¡of¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡MyValueTypeWithReferenceType¡¡is¡¡the¡¡same¡¡as¡¡the¡¡previous¡¡code¡¡examples£»¡¡but¡¡a¡¡second¡¡allocation¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡MyReferenceType¡¡is¡¡required¡¡because¡¡MyReferenceType¡¡is¡¡a¡¡reference¡¡type¡£¡¡Had¡¡MyReferenceType¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡been¡¡a¡¡value¡¡type£»¡¡the¡¡allocation¡¡would¡¡not¡¡have¡¡been¡¡necessary¡£¡¡But¡¡if¡¡you¡¡allocate¡¡a¡¡value¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡type¡¡like¡¡a¡¡reference¡¡type£»¡¡the¡¡piler¡¡will¡¡ignore¡¡the¡¡directive¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡107¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡4¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡D¡¡AT¡¡A¡¡¡¡S¡¡TR¡¡U¡¡CT¡¡U¡¡R¡¡E¡¡S£»¡¡¡¡¡¡DE¡¡CI¡¡SI¡¡ON¡¡S£»¡¡¡¡¡¡A¡¡N¡¡D¡¡¡¡¡¡L¡¡O¡¡OP¡¡S¡¡85¡¡
¡¡¡¡¡¡¡¡¡¡Running¡¡the¡¡test¡¡code¡¡results¡¡in¡¡the¡¡following£º¡¡
var¡¡value=0¡¡copiedVar¡¡value=0¡¡
var¡¡value=10¡¡copiedVar¡¡value=10¡¡
¡¡¡¡¡¡¡¡¡¡When¡¡you¡¡assign¡¡and¡¡modify¡¡an¡¡embedded¡¡reference¡¡type£»¡¡the¡¡reference¡¡type¡¡instance¡¡is¡¡¡¡
modified¡¡for¡¡both¡¡variables¡£¡¡In¡¡this¡¡case£»¡¡when¡¡we¡¡assigned¡¡the¡¡value¡¡type£»¡¡the¡¡contents¡¡were¡¡¡¡
copied£»¡¡including¡¡the¡¡pointer¡¡to¡¡the¡¡reference¡¡type¡£¡¡
¡¡¡¡¡¡¡¡¡¡Table¡¡4¡1¡¡summarizes¡¡the¡¡behavior¡¡of¡¡types¡¡when¡¡the¡¡allocated¡¡variable¡¡is¡¡assigned¡¡to¡¡¡¡
another¡¡variable¡¡and¡¡the¡¡data¡¡member¡¡from¡¡the¡¡original¡¡is¡¡modified¡£¡¡For¡¡example£»¡¡if¡¡the¡¡code¡¡¡¡
is¡¡custom2¡¡=¡¡custom1¡¡custom1¡£member¡¡=¡¡£§new¡¡value£§£»¡¡what¡¯s¡¡the¡¡value¡¡of¡¡custom2¡£member£¿¡¡¡¡
Table¡¡4¡1¡£¡¡Behavior¡¡When¡¡the¡¡Allocated¡¡Variable¡¡Is¡¡Assigned¡¡to¡¡Another¡¡Variable¡¡and¡¡the¡¡Data¡¡¡¡
Member¡¡from¡¡the¡¡Original¡¡Is¡¡Modified¡¡
Type¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Behavior¡¡
Value¡¡type¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Assigned¡¡data¡¡member¡¡is¡¡not¡¡modified¡¡
Reference¡¡type¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Assigned¡¡data¡¡member¡¡is¡¡modified¡¡
Value¡¡type¡¡embedding¡¡value¡¡type¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Assigned¡¡embedded¡¡data¡¡member¡¡is¡¡not¡¡modified¡¡
Value¡¡type¡¡embedding¡¡reference¡¡type¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Assigned¡¡embedded¡¡data¡¡member¡¡is¡¡modified¡¡
Reference¡¡type¡¡embedding¡¡value¡¡type¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Assigned¡¡embedded¡¡data¡¡member¡¡is¡¡modified¡¡
Reference¡¡type¡¡embedding¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Assigned¡¡embedded¡¡data¡¡member¡¡is¡¡modified¡¡
reference¡¡type¡¡
Value¡¡Types¡¡and¡¡Parameters¡¡
Another¡¡value¡¡type¡¡constraint¡¡relates¡¡to¡¡how¡¡variables¡¡are¡¡stored¡¡and¡¡manipulated¡¡when¡¡they¡¡¡¡
are¡¡passed¡¡via¡¡a¡¡method¡£¡¡Suppose¡¡you¡¡create¡¡a¡¡method¡¡that¡¡has¡¡as¡¡parameters¡¡a¡¡value¡¡type¡¡and¡¡¡¡
a¡¡reference¡¡type¡£¡¡If¡¡in¡¡the¡¡method¡¡the¡¡parameters¡¡are¡¡modified£»¡¡what¡¡modifications¡¡does¡¡the¡¡¡¡
caller¡¡of¡¡the¡¡method¡¡see£¿¡¡Consider¡¡the¡¡following¡¡code£º¡¡
Sub¡¡Method£¨ByVal¡¡value¡¡As¡¡MyValueType£»¡¡ByVal¡¡reference¡¡As¡¡MyReferenceType£©¡¡
¡¡¡¡value¡£value¡¡=¡¡10¡¡
¡¡¡¡reference¡£value¡¡=¡¡10¡¡
End¡¡Sub¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡caller¡¡can¡¡pass¡¡in¡¡instances¡¡of¡¡a¡¡value¡¡type¡¡and¡¡a¡¡reference¡¡type¡¡that¡¡are¡¡manipulated¡¡¡¡
in¡¡the¡¡context¡¡of¡¡the¡¡method¡£¡¡Now¡¡let¡¯s¡¡call¡¡Method£¨£©¡¡with¡¡the¡¡following¡¡code£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡108¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
86¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡4¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡D¡¡AT¡¡A¡¡¡¡S¡¡TR¡¡U¡¡CT¡¡U¡¡R¡¡E¡¡S£»¡¡¡¡¡¡DE¡¡CI¡¡SI¡¡ON¡¡S£»¡¡¡¡¡¡A¡¡N¡¡D¡¡¡¡¡¡L¡¡O¡¡OP¡¡S¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡value¡¡As¡¡MyValueType¡¡=¡¡New¡¡MyValueType£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡reference¡¡As¡¡MyReferenceType¡¡=¡¡New¡¡MyReferenceType£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Method£¨value£»¡¡reference£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨value¡¡value=¡¨¡¡&¡¡value¡£value¡¡&¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¨¡¡reference¡¡value=¡¨¡¡&¡¡reference¡£value£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡calling¡¡code¡¡instantiates¡¡the¡¡types¡¡MyValueType¡¡and¡¡MyReferenceType£»¡¡calls¡¡the¡¡method¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Method£¨£©£»¡¡and¡¡then¡¡inspects¡¡the¡¡value¡¡of¡¡the¡¡data¡¡member¡¡value¡¡from¡¡the¡¡value¡¡and¡¡reference¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡types¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Running¡¡the¡¡code¡¡will¡¡generate¡¡output¡¡similar¡¡to¡¡the¡¡following£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡value¡¡value=0¡¡reference¡¡value=10¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡executed¡¡code¡¡shows¡¡that¡¡the¡¡value¡¡type¡¡£¨MyValueType£©¡¡data¡¡member¡¡was¡¡not¡¡altered£»¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡whereas¡¡the¡¡reference¡¡type¡¡£¨MyReferenceType£©¡¡data¡¡member¡¡was¡¡altered¡£¡¡This¡¡is¡¡correct£»¡¡and¡¡it¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡demonstrates¡¡that¡¡when¡¡you¡¡call¡¡a¡¡method£»¡¡you¡¡are¡¡assigning¡¡the¡¡parameters¡¡of¡¡the¡¡method¡¡to¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡variables¡¡in¡¡the¡¡