|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
我认为,可以通过更加简单的首次编译,而增加第二次编译的负担,来提高net网页编程的运行效率。只是将net网页编程源代码进行简单的等价转换,而不假设编译成某种虚拟机器的目标格式,而由本地编译器针对性的二次编译。当跨assemblies的时分要出格注重二者的区分,请看这篇文章
ifthescopeofyourconstantislimitedtojustoneassembly,class,orsmaller(youcandefineaconstinsideamethod),thisisnotabigdeal.However,iftheconstisvisibleoutsidetheassemblyitisdefinedin,wemustbewary!Becausetheconst’svalueissubstitutedatcompiletime,thismeansthatiftheassemblythatdefinestheconstchangesitsvalue,butthecallingassemblyisn’trecompiled,thenthecallingassemblywillstillseetheoriginalvalue.
Let’sillustrate.AssumeaclasslibrarycalledShapes.DLLthatdefinesthis:
- 3:publicconstdoublePi=3.14;
复制代码
Nowlet’sassumeaseparateprogramcalledDrawing.EXEaddsareferencetoShapes.DLLandusestheconst:
- 1:publicstaticclassDrawing
复制代码
Ifwerunthis,weget:
Nowlet’ssayduringtheQAprocesssomeonedecidesthatthisvalueofPiisnotpreciseenoughandchangesthedefinition:
AndtheyrebuildtheShapes.DLLandjustdropitintothedeploymentdirectoryforDrawing.EXEwithoutrebuildingit.WhathappensifwerunDrawing.EXEagainwithoutrecompiling?Weget:
Whoa!EventhoughwechangedthevalueofPiinourreferencedassemblyanddeployedittowhereDrawing.EXEexpecteditandDrawing.EXEloadedit,itstillprints3.14.Thisisbecauseconstisacompile-timesubstitution.Thus,ifyouchangethevalueofaconst,itwillnotbepickedupuntilthecodeusingitisrecompiledaswell.IfwerecompileandrunDrawing.EXE,wewillget:
Thus,constshouldbeusedmainlyforvaluesthatarenotsubjecttochange,orfreelyifthescopeoftheconstislimitedtothesameassemblyorsmaller.
我之所以想学。NET,是因为一直觉的BILLGATES好厉害,希望有一天能去微软,虽然现在还距离遥远,呵呵:) |
|