ãã®èŠåã®ãªã¹ãã®ç®æšã¯ã䟿å©ã§å®çšçãªCïŒã³ãŒããèšè¿°ããããã®æšæºãèšå®ããããšã§ãã ãã¡ãããç§ãã¡ã¯äœæãããã®ãç·Žç¿ããŸãã ãããã®ã«ãŒã«ã¯ãAvivaSolutionsã§ã®æ¥ã ã®æ¥åã®æ ¹åºã«ããæšæºã®1ã€ã§ãã ãããã®ãã¹ãŠã®ã«ãŒã«ã«æ確ãªæ ¹æ ãããããã§ã¯ãããŸããã ãããã®ããã€ãã¯ãåã«æšæºãšããŠåãå ¥ããããŠããŸãã
VisualStudio Static Code Analyzer ïŒFxCompãšãåŒã°ããŸãïŒããã³StyleCopã¯ãã³ã³ãã€ã«ãããã¢ã»ã³ããªãåæããããšã«ãããå€ãã®ã³ãŒãã£ã³ã°ããã³ã¹ã¿ã€ãªã³ã°ã«ãŒã«ãèªåçã«é©çšã§ããŸãã ã³ã³ãã€ã«æã«åæãå®è¡ãããããã«ããŸãã¯é£ç¶ãã«ããŸãã¯æ¯æ¥ã®ãã«ãã®äžå¯æ¬ ãªéšåã§ããããã«ãããããæ§æã§ããŸãã ãã®ããã¥ã¡ã³ãã§ã¯ãè¿œå ã®èŠåãšæšå¥šäºé ãè¿œå ããŠããŸããããµããŒããµã€ãwww.csharpcodingguidelines.comã«ã¯ã䜿çšããŠããã³ãŒãããŒã¹ã«å¿ããŠå¿ èŠãªã³ãŒãåæèŠåã®ãªã¹ããèšèŒãããŠããŸãã
ãªãããã䜿çšããå¿ èŠããããŸããïŒ
ã³ãŒããæžãããã®æšæºããåµé æ§ã®èªç±ã䟵害ããããã€ãã®å¶éãšèãã人ãããŸãã ããã§ãããã®ã¢ãããŒãã¯æ£åœåãããé·å¹Žã«ããã£ãŠãã¹ããããŠããŸãã ãªãã§ïŒ ãã¹ãŠã®éçºè ããããç¥ã£ãŠããããã§ã¯ãªãããã§ãïŒ
- ã³ãŒããå€æŽãããããç解ããã®ã«10åæéãããããŸã
- ãã¹ãŠã®éçºè ãCïŒã§åºæ¬æ§é ã䜿çšããããšã®è€éããç¥ã£ãŠããããã§ã¯ãããŸããã
- ããšãã°ã
IDisposable
ãŸãã¯LINQãé 延å®è¡ã§äœ¿çšããå Žåãªã©ãã©ã®.NET Frameworkã®èŠåã«åŸãã¹ããã誰ããç¥ã£ãŠããããã§ã¯ãããŸããã - åé¡ã«å¯Ÿãããã©ã€ããŒããªãœãªã¥ãŒã·ã§ã³ãããã©ãŒãã³ã¹ãã»ãã¥ãªãã£ãè€æ°èšèªã®ãµããŒããªã©ã«ã©ã®ããã«åœ±é¿ãããã誰ããç¥ã£ãŠããããã§ã¯ãããŸããã
- ãã¹ãŠã®éçºè ãçŸããããããå¥ã®éçºè ã®æœè±¡çãªã³ãŒããç解ã§ããããã§ã¯ãããŸãã
åºæ¬åå
ç§ã¯ã³ã³ãµã«ã¿ã³ããšããŠä»äºã§åºäŒã£ãå€ãã®éèªæãªãã®ããããã³ãŒããæžãããã®å°ãªããšã1ã€ã®æšå¥šäºé ã§èšåã«å€ããŸãã æ®å¿µãªããããã®ã¬ã€ãã®ç¯å²ã¯åççãªç¯å²å ã§ããå¿ èŠããããŸãã ãã ããåå¿è ã®éçºè ãäœãèããŠãããã®ããã¥ã¡ã³ãã§äœãèšåããŠããªããã°ãããã泚ç®ã«å€ããªããšããæå³ã§ã¯ãããŸããã
åè¿°ã«åºã¥ããŠããã®ããã¥ã¡ã³ãã§ã¯çºçããå¯èœæ§ã®ãããã¹ãŠã®ç¶æ³ãã«ããŒã§ããããã§ã¯ãªãããšãç解ããå¿ èŠããããŸãã è°è«ã®äœå°ãããå Žåã¯ãã³ã³ããã¹ãã«é¢ä¿ãªããããããç¶æ³ã«é©çšãããåºæ¬ååãåç §ããå¿ èŠããããŸãã ãããã«ã¯ä»¥äžãå«ãŸããŸãã
- æå°ãµãã©ã€ãºã®åç ã ãæå°éã®é©ãã®ã«ãŒã«ãã ä»ã®éçºè ãæ··ä¹±ãããããã³ãŒããããç解ãããããããããªãããã«ãã¿ã¹ã¯ã«å¯ŸããŠæãæçœãªãœãªã¥ãŒã·ã§ã³ãéžæããå¿ èŠããããŸãã
- ã·ã³ãã«ãªæãã ïŒãŸãã¯KISSïŒãç¶æããŸãã æåéã-ããã£ãšç°¡åã«ãããã銬鹿ããŠãããã ãã®ååã¯ãã¿ã¹ã¯ã®è§£æ±ºã®ããã«æãç°¡åãªè§£æ±ºçãéžæããå¿ èŠããããšè¿°ã¹ãŠããŸã
- ããªãã¯ãŽããå¿ èŠã§ã¯ãªã ïŒãŸãã¯YAGNIïŒã ãå¿ èŠãããŸãããã ãçŸåšã®åé¡ã®è§£æ±ºã«åãçµãã§ãã ãããå°æ¥åœ¹ã«ç«ã€ãšæããããšãã£ãŠã³ãŒããæžããªãã§ãã ããïŒå°æ¥ãäºæž¬ã§ããŸããïŒïŒã
- èªåãç¹°ãè¿ããªãã§ãã ãã ïŒãŸãã¯DRYïŒã ãç¹°ãè¿ããªãã§ãã ãããã ãã®ååã¯ãã 3ã€ã®ãã¥ãŒãªã¹ãã£ãã¯ã«ãŒã« ããå¿ããã«ãã³ãŒãã®è€è£œãæ§ããããšããå§ãããŸãã
ã³ãŒãã¯éåžžã«è¯ãèŠãããããããªããšããäºå®ã«ãããããããä»ã®éçºè ã«ç解ã§ãããã©ãããããããããªããæåŸ ããã¹ãæ¯ãèããæã£ãŠãããã©ãããå°æ¥èµ·ãããããããªãåé¡ã解決ããããšããŠããŸããïŒ ããã§ãªãå Žåã¯ããªãã¡ã¯ã¿ãªã³ã°ãæ€èšããå¿ èŠããããŸãã
ã©ããã£ãŠå§ããŸããïŒ
- ãã¹ãŠã®éçºè ã«ããã®ããã¥ã¡ã³ããå°ãªããšã1åã¯æ³šææ·±ãèªãããã«äŸé ŒããŠãã ããã ããã«ãããã©ã®ååãå«ãŸããŠããããç解ããããšãã§ããŸãã
- ãã®ããã¥ã¢ã«ãžã®çããªã³ã¯ã®å°å·ãããã³ããŒãæå ã«ããã€ãããããšã確èªããŠãã ããã
- ãããžã§ã¯ããã§ãã¯ãªã¹ãã«æãéèŠãªã«ãŒã«ãå«ãããã¢ã¬ãã¥ãŒäžã«æ®ãã®ã«ãŒã«ãžã®æºæ ããã§ãã¯ããŸã
- ãããžã§ã¯ãã«é©çšããéçåæã«ãŒã«ã決å®ããã©ããã«èšè¿°ããŸãã ããšãã°ãTFSããŒã ãµã€ãã§ããããå ¬éããããæšæºã®Visual Studioã«ãŒã«ã»ãããäœæããŸãã
- äŒç€ŸãŸãã¯æ¥çã«åºæã®çšèªãååãããã³æŠå¿µã§ã«ã¹ã¿ã ã³ãŒãåæèŸæžãå å®ãããŸãã ããããªããšãéçã¢ãã©ã€ã¶ãŒã¯ãå éšèŸæžã«å«ãŸããªãæ§é ã«é¢ããèŠåã衚瀺ããŸã
- VisualStudioãèšå®ããŠãéžæããéçåæã«ãŒã«ããªãªãŒã¹ãã«ãã®äžéšãšããŠå®è¡ãããããšã確èªããŸãã ãã®åŸããããã¯éçºãšãããã°ã劚ããŸãããããªãªãŒã¹æ§æã«åãæ¿ãããšãã«éå§ã§ããŸãã
- ãããžã§ã¯ãã®ãã§ãã¯ãªã¹ãã«ãã§ãã¯ãã€ã³ããè¿œå ããŠæšå¥šäºé ã«åŸã£ãŠãã¹ãŠã®æ°ããã³ãŒãããããã«äžèŽããããšã確èªãããããªããžããªã«éä¿¡ããåã«ã³ãŒããã«ãŒã«ã«æºæ ããŠãããã©ããã確èªããå Žåã¯é©åãªãã§ãã¯ã€ã³ããªã·ãŒã䜿çšããŸã
- ReSharperã«ã¯ã€ã³ããªãžã§ã³ããªã³ãŒãã€ã³ã¹ãã¯ã¿ãŒããããäžéšã®æ§æã§ã¯ããã®ã¬ã€ãã®èŠä»¶ã®å€ããæ¢ã«ãµããŒãããŠããŸãã åœåèŠåã«æºæ ããŠããªãã³ãŒãïŒãã¹ã«ã«ã®åœåã¹ã¿ã€ã«ãã©ã¯ãè¡šèšãªã©ïŒãèªåçã«åŒ·èª¿è¡šç€ºãããããã³ãŒããèŠã€ããŠãã®ä»ã®ãã§ãã¯ãè¡ããŸãã ãããä¿®æ£ããã«ã¯ã1åã®ããŠã¹ã¯ãªãã¯ïŒãŸãã¯ãããããŒã®çµã¿åããïŒã§ååã§ãã
- ReSharperã«ã¯ããšããããã¯ã©ã¹ãŸãã¯ã€ã³ã¿ãŒãã§ã€ã¹ã®ã¡ã³ããŒã®äžè¬çãªã¢ã€ãã¢ãæäŸãããã¡ã€ã«æ§é ãŠã£ã³ããŠããããç°¡åãªãã©ãã°ã¢ã³ãããããã§ç°¡åã«ç§»åã§ããŸãã
- GhostDocã䜿çšãããš ãããŒããŒãã·ã§ãŒãã«ããã䜿çšããŠXMLã³ã¡ã³ããçæã§ããŸãã ãã¹ãŠã®é åã¯ãMSDNããã¥ã¡ã³ãã®ã¹ã¿ã€ã«ã«æ£ç¢ºã«åŸãããšãã§ããããšã§ãã ãã ãããã®ããŒã«ãä¹±çšãããéå§ãšããŠã®ã¿äœ¿çšããŠãã ãã
ãªããããäœæããã®ã§ããïŒ
ãã®ã¢ã€ãã¢ã¯2002幎ã«Vick HartorgïŒPhilips Medical SystemïŒãšç§ãCïŒ1.0ã®ã³ãŒãã£ã³ã°æšæºãæžãããšãä»»ããããšãã«çãŸããŸããã ãã以æ¥ãVisual Studio 2010ã§å°å ¥ãããçµéšããã¢ã¬ãã¥ãŒãæ°ãããã©ã°ã€ã³ã«åºã¥ããŠèŠåãå®æçã«è¿œå ãåé€ãå€æŽããŸãããããã«ã Robert Martinã®æ¬ãClean CodeïŒCreatingãAnalyzingãand Refactoringããèªãã åŸã圌ã®ã¢ã€ãã¢ã«è奮ããŸãããããã®ããã€ããã«ãŒã«ãšããŠå«ããããšã«ããŸããã ãã®ææžã¯æ±ºããŠåœŒã®æ¬ã®ä»£æ¿ã§ã¯ãªãããšã«æ³šæãããã 圌ã®æèšã®æ ¹åºã«ããååããã£ãããšç解ããããã«ã圌ã®æ¬ãèªãããšãå¿ãããå§ãããŸãã ããã«ãã³ãŒããæžããšããååãããã€ãã®èšèšååã§è£ãããšã«ããŸããã ãããã¯ç¡èŠããã«ã¯éèŠããããããé«å質ã®ã³ãŒããéæããã®ã«å€§ããªåœ±é¿ãåãŒããŸãã
ãããã®æšå¥šåºæºã¯ãããŸããïŒ
ãã®ããã¥ã¡ã³ãã§ã¯ããããã®æšå¥šäºé ãå³å®ããå¿ èŠããããšã¯è¿°ã¹ãŠããŸããã ãŸãããããã®æšå¥šäºé ãä»ã®æšå¥šäºé ãããéèŠã§ãããšã䞻匵ããŠããŸããã ãã ããã©ã®æšå¥šäºé ãéèŠã§ãããããããžã§ã¯ãã§èš±å®¹ãããæšæºããã®éžè±ãçåãçããå Žåã®ã³ã³ãµã«ã¿ã³ããããã³ãœãŒã¹ã³ãŒãã«äœ¿çšããã¬ã€ã¢ãŠãã決å®ããããšããå§ãããŸãã æããã«ãå®éã®ä»äºã«çæããåã«ãããã®æ±ºå®ãäžããªããã°ãªããªãã®ã¯ããªãã§ãã
ããªãã®éžæãå©ããããã«ãç§ã¯åæšå¥šäºé ã®éèŠæ§ãå²ãåœãŠãŸããïŒ
ã決ããŠç¡èŠããŠã¯ãªããªãã«ãŒã«ã§ããããã¹ãŠã®ç¶æ³ã«é©çšãããŸããã
-ãã®ã«ãŒã«ã«åŸãããšã匷ããå§ãããŸãã
-ãã®èŠåã«åŸãããšããå§ãããŸããããã¹ãŠã®ç¶æ³ã«é©çšãããããã§ã¯ãããŸããã
çµè«ãšããŠãç§ã¯ãã¹ãŠã®çæãããã³ãŒããæšæºã«æºæ ããå¿ èŠã¯ãªããšèšãããã§ãã ãã ããã³ãŒãã®çæã«äœ¿çšããããã³ãã¬ãŒããå€æŽã§ããå Žåã¯ããããã®æšå¥šäºé ã«æé©ãªã³ãŒããäœæããããã«ããŠãã ããã
ãã£ãŒãããã¯ãšå 責äºé
ãã®ããã¥ã¡ã³ãã¯ãã³ãã¥ããã£ã¡ã³ããŒãããã°èšäºããªã³ã©ã€ã³ãã£ã¹ã«ãã·ã§ã³ãããã³CïŒã§ã®é·å¹Žã®éçºã«ããå€å€§ãªè²¢ç®ã®ãããã§äœæãããŸããã 質åãã³ã¡ã³ããææ¡ãããå Žåã¯ã dennis.doomen @ avivasolutions.nlãŸãã¯Twitterã®http://twitter.com/ddoomenã« ã¡ãŒã«ããã ããã æ°ããã¢ã€ãã¢ãçµéšãã³ã¡ã³ãã«åºã¥ããŠããã®ããã¥ã¡ã³ããå®æçã«ç¢ºèªããåçºè¡ããããåªããŸãã
ãããã®æšå¥šäºé ã¯ãæ£ããCïŒã³ãŒãã«å¯Ÿããç§ã®ããžã§ã³ã®ã¿ãåæ ããŠããããšã«æ³šæããŠãã ããã Aviva Solutionsã¯ãæ¬æžã«èšèŒãããŠããæšæºã®é©çšã«èµ·å ããçŽæ¥çãŸãã¯éæ¥çãªæ害ã«ã€ããŠè²¬ä»»ãè² ããŸããã
éå¶å©ç®çããã³å éšäœ¿çšã®ããã«ããã®ããã¥ã¡ã³ãããã³ãã®ããã¥ã¢ã«ã®ç°¡åãªåç §ãã³ããŒãæ¹å€ãããã³é åžããèš±å¯ãäžããããŸãã ãã ããæåã«Aviva Solutionsããæžé¢ã«ããèš±å¯ãåŸãããšãªããåæ¥ç®çã§ãã®ããã¥ã¡ã³ãã®é åžãæ¹å€ããŸãã¯è€è£œãè¡ãããšã¯ã§ããŸããã
ã¯ã©ã¹èšèšã¬ã€ãã©ã€ã³
AV1000ã¯ã©ã¹ãŸãã¯ã€ã³ã¿ãŒãã§ã€ã¹ã«ã¯1ã€ã®ç®çã®ã¿ãå¿ èŠã§ã
ã¯ã©ã¹ãŸãã¯ã€ã³ã¿ãŒãã§ãŒã¹ã¯ã䜿çšãããã·ã¹ãã å ã§åäžã®ç®çãæã€å¿ èŠããããŸãã éåžžãã¯ã©ã¹ã¯ç®çã®1ã€ãæãããŸããããšãã°ãé»åã¡ãŒã«ãISBNïŒåœéæšæºå³æžçªå·ïŒãªã©ã®ã¿ã€ããèšè¿°ããããããžãã¹ããžãã¯ãæœè±¡åããããããŒã¿æ§é ãèšè¿°ããããä»ã®ã¯ã©ã¹éã®çžäºäœçšãæ åœããŸãã 圌ã¯æ±ºããŠãããã®ã¿ã¹ã¯ãèªåã§çµã¿åãããŠã¯ãããŸããã ãã®ã«ãŒã«ã¯ãSOLIDã®ååã®1ã€ã§ããåäžè²¬ä»»ååãšããŠç¥ãããŠããŸãã
ãã³ã ïŒååã«ãAndããšããåèªãå«ãŸããã¯ã©ã¹ã¯ããã®èŠåã«æããã«éåããŠããŸãã
ãã³ã ïŒ ãã¶ã€ã³ãã¿ãŒã³ã䜿çšããŠãã¯ã©ã¹éã§ããåãããŸãã ãã¿ãŒã³ãã¯ã©ã¹ã«é©çšã§ããªãå Žåã¯ãããããããŸãã«ãå€ãã®è²¬ä»»ãè² ããŸãã
泚 ïŒåãèšè¿°ããã¯ã©ã¹ãäœæããå Žåãäžå€ã«ããããšã§ãã®äœ¿çšãå€§å¹ ã«ç°¡çŽ åã§ããŸãã
AV1001ã³ã³ã¹ãã©ã¯ã¿ãŒã䜿çšããŠã¯ã©ã¹ã®æ°ããã€ã³ã¹ã¿ã³ã¹ãäœæãããã®çµæãããã«äœ¿çšã§ãããªããžã§ã¯ããååŸããŸã ã
äœæããããªããžã§ã¯ãã¯ãé©çšããäºå®ã®ãªãç®çã«äœ¿çšããåã«ãè¿œå ã®ããããã£ãèšå®ããå¿ èŠã¯ãããŸããã ããã«ãã³ã³ã¹ãã©ã¯ã¿ãŒã3ã€ä»¥äžã®ãã©ã¡ãŒã¿ãŒïŒAV1561èŠåã«éåããïŒãå¿ èŠãšããå Žåãã¯ã©ã¹ãé床ã®è²¬ä»»ïŒAV1000èŠåã«éåããïŒãåŒãåããå¯èœæ§ããããŸãã
AV1003ã€ã³ã¿ãŒãã§ã€ã¹ã¯å°ããã1ã€ã®ã¿ã¹ã¯ã«çŠç¹ãåãããå¿ èŠããããŸãã
ã€ã³ã¿ãŒãã§ã€ã¹ã«ã¯ããã®ç®çãŸãã¯ã·ã¹ãã ã§æãã圹å²ãæ確ã«èª¬æããååãå¿ èŠã§ãã åãã¯ã©ã¹ã«å±ããŠãããšããçç±ã ãã§ãççµåèŠçŽ ã1ã€ã®ã€ã³ã¿ãŒãã§ã€ã¹ã«çµåããªãã§ãã ããã åŒã³åºãããã¡ãœãããæ åœããæ©èœã«åºã¥ããŠããŸãã¯ãã®ã€ã³ã¿ãŒãã§ã€ã¹ãå®è¡ããç¹å®ã®ã¿ã¹ã¯ã«åºã¥ããŠãã€ã³ã¿ãŒãã§ã€ã¹ãèšå®ããŸãã ãã®èŠåã¯ã Interface Segregation PrincipleãšããŠç¥ãããŠããŸãã
AV1004åºæ¬ã¯ã©ã¹ã§ã¯ãªãã€ã³ã¿ãŒãã§ãŒã¹ã䜿çšããŠãè€æ°ã®å®è£ ããµããŒãããŸã
ã¯ã©ã¹ã®æ¡åŒµãã€ã³ããèšå®ããå Žåã¯ãåºæ¬ã¯ã©ã¹ã§ã¯ãªããã€ã³ã¿ãŒãã§ã€ã¹ãšããŠå ¬éããŸãã ãã®æ¡åŒµãã€ã³ãã®ãŠãŒã¶ãŒã«ãæãŸãããªãåäœãããå¯èœæ§ã®ããåºæ¬ã¯ã©ã¹ã«åºã¥ããŠå®è£ ã匷å¶ããããšã¯æãŸãããããŸããã ãã ãã䟿å®äžãããã©ã«ãã®å®è£ ïŒæœè±¡ã¯ã©ââã¹ïŒãäœæããŠãéå§ç¹ãšããŠäœ¿çšã§ããŸãã
AV1005ã€ã³ã¿ãŒãã§ã€ã¹ã䜿çšããŠãã¯ã©ã¹éã®ççµåãå®è£ ããŸã
ã€ã³ã¿ãŒãã§ã€ã¹ã¯ãççµåã¯ã©ã¹ãå®è£ ããããã®åªããããŒã«ã§ãã
- ãããã¯ãåæ¹åæ¥ç¶ãåé¿ããã®ã«åœ¹ç«ã¡ãŸãã
- ããã«ãããããå®è£ ãå¥ã®å®è£ ã«ç°¡åã«çœ®ãæããããšãã§ããŸãã
- ã¢ã¯ã»ã¹ã§ããªãå€éšãµãŒãã¹ãŸãã¯ãªãœãŒã¹ããé皌åç°å¢ã§äœ¿çšããäžæã¹ã¿ãã«çœ®ãæããããšãã§ããŸã
- åäœãã¹ãäžã«ãçŸåšã®å®è£ ããããŒã®å®è£ ã«çœ®ãæããããšãã§ããŸãã
- äŸåæ§æ³šå ¥ãæ³šå ¥ããããã®ãã¬ãŒã ã¯ãŒã¯ã䜿çšãããšãèŠæ±ãããã€ã³ã¿ãŒãã§ãŒã¹ã«å¿ããŠã¯ã©ã¹éžæã®ããžãã¯ã1ãæã§åéã§ããŸãã
AV1008éçã¯ã©ã¹ãé¿ãã
æ¡åŒµã¡ãœãããäœæããããã«äœ¿çšãããéçã¯ã©ã¹ãé€ããéçã¯ã©ã¹ã¯éåžžã«é »ç¹ã«äžæ£ãªã³ãŒãã«ã€ãªãããŸãã ããã«ãéåžžã«æŽç·ŽãããããŒã«ã«é ŒããŸã§ãå¯èœã§ããã°åé¢ããŠãã¹ãããããšã¯éåžžã«å°é£ã§ãã
泚 ïŒæ¬åœã«éçã¯ã©ã¹ãå¿ èŠãªå Žåã¯ãéçãšããŠããŒã¯ã
static
ã ãã®å Žåãã³ã³ãã€ã©ã¯ãã®ã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ã®äœæãçŠæ¢ããæåã®åŒã³åºãã®åã«ã¯ã©ã¹ãåæåããŸãã ããã«ããããã©ã€ããŒãã³ã³ã¹ãã©ã¯ã¿ãŒã䜿çšããå¿ èŠããªããªããŸãã
AV1010æ°ããããŒã¯ãŒãã®èåŸã«ç¶æ¿ãããèŠçŽ ãé ããªã
ããã¯ããªããžã§ã¯ãæåããã°ã©ãã³ã°ã®æãéèŠãªååã®1ã€ã§ããããªã¢ãŒãã£ãºã ãšççŸããã ãã§ãªããåã¯ã©ã¹ã®ç解ãå°é£ã«ããŸãã 次ã®2ã€ã®ã¯ã©ã¹ãæ€èšããŠãã ããã
public class Book { public virtual void Print() { Console.WriteLine("Printing Book"); } } public class PocketBook : Book { public new void Print() { Console.WriteLine("Printing PocketBook"); } }
ãã®å Žåãã¯ã©ã¹ã¯ã䜿çšæã«æåŸ ããåäœãããŸããã
PocketBook PocketBook = new PocketBook (); pocketBook.Print (); // "Printing PocketBook" ((Book)pocketBook).Print(); // "Printing Book"
ããã§ã¯ãåºæ¬ã¯ã©ã¹ãžã®åç §ãéããŠåŒã³åºããããã掟çã¯ã©ã¹ã®ã¡ãœãããšããŠåŒã³åºããããã«ãã£ãŠã
Print
ã¡ãœããã®åäœãç°ãªãããšã瀺ããŠããŸãã
åºæ¬åã䜿çšããAV1011é¢æ°ã¯ãåºæ¬åã®ãµãã¿ã€ããç¥ããªããŠã䜿çšã§ããå¿ èŠããããŸã
ã€ãŸããç¶æ¿ãããã¯ã©ã¹ã®åäœã¯ãåºæ¬ã¯ã©ã¹ã§æå®ãããåäœãšççŸããŠã¯ãªããŸãããã€ãŸããç¶æ¿ãããã¯ã©ã¹ã®åäœã¯ãåºæ¬åã®å€æ°ã䜿çšããã³ãŒãã§æåŸ ãããŸãã ãã®ã«ãŒã«ã®éåã®æãæåãªäŸã¯ãããŒã¹ã¯ã©ã¹ã¡ãœããããªãŒããŒã©ã€ããããšãã«çºçãã
NotImplementedExeption
äŸå€ã§ãã
泚 ïŒãã®ååã¯ã SOLIDååã®1ã€ã§ããBarbara Lisk Substitution PrincipleãšããŠãç¥ãããŠããŸãã
AV1013åºæ¬ã¯ã©ã¹ãã掟çã¯ã©ã¹ãåç §ããªãã§ãã ãã
åã¯ã©ã¹ã®èŠªã¯ã©ã¹ã«äŸåé¢ä¿ããããšããªããžã§ã¯ãæåããã°ã©ãã³ã°ã®ååã«éåããä»ã®éçºè ãåºæ¬ã¯ã©ã¹ããç¶æ¿ããããšã¯ã§ããŸããã
AV1014ãªããžã§ã¯ãã¯ããã®ãªããžã§ã¯ãã«çŽæ¥é¢é£ããŠããªãä»ã®ãªããžã§ã¯ãã®éãããç¥èãæã£ãŠããå¿ èŠããããŸãã
ã³ãŒãã以äžã®ã³ãŒãã«äŒŒãŠããå Žåã ãã¡ãã«ã®æ³åã«éåããŠããŸãã
someObject.SomeProperty.GetChild().Foo();
ãªããžã§ã¯ãã¯ãäŸåããã¯ã©ã¹ãžã®ã¢ã¯ã»ã¹ãéããªãããã«ããå¿ èŠããããŸãããŠãŒã¶ãŒãªããžã§ã¯ãã¯ãããããã£ãã¡ãœããã誀ã£ãŠäœ¿çšããŠãèåŸã®ãªããžã§ã¯ãã«ã¢ã¯ã»ã¹ããå¯èœæ§ãããããã§ãã ããããããšã§ãåŒã³åºãããã³ãŒãã䜿çšããŠããã¯ã©ã¹ãšçµ±åã§ããããã«ãªããŸãã ãããã£ãŠãå°æ¥ãããå®è£ ãå¥ã®å®è£ ã«çœ®ãæããå¯èœæ§ãå¶éããŸãã
泚 ïŒFluent Interfaceãå®è£ ããã¯ã©ã¹ã䜿çšãããšããã®èŠåã«éåããŠããããã«èŠããå ŽåããããŸãã ãã ããåŒã³åºãããã¡ãœããã¯ãåã«åŒã³åºãã³ã³ããã¹ãã次ã®ãªã³ã¯ã«æž¡ããŸãã ãããã£ãŠãããã¯è«äºãåŒãèµ·ãããŸããã
äŸå€ ïŒå¶åŸ¡ãšãã¬ãŒã ã¯ãŒã¯ã®å転ã䜿çšããå ŽåãäŸåæ§ã®æ³šå ¥ã§ã¯å€ãã®å ŽåãäŸåé¢ä¿ããããªãã¯ããããã£ãšããŠå ¬éããå¿ èŠããããŸãã ãããã®ããããã£ãäŸåæ§æ³šå ¥ã®å®è£ 以å€ã«äœ¿çšãããªãéããããã¯ã«ãŒã«éåãšã¯ã¿ãªãããŸããã
AV1020åæ¹åã®äŸåé¢ä¿ãåé¿ãã
åæ¹åäŸåãšã¯ã2ã€ã®ã¯ã©ã¹ãäºãã®ãããªãã¯ã¡ãœãããèªèããŠããããäºãã®å éšåäœã«äŸåããŠããããšãæå³ããŸãã ããã2ã€ã®ã¯ã©ã¹ã®ããããããªãã¡ã¯ã¿ãªã³ã°ãŸãã¯çœ®æããã«ã¯ãäž¡æ¹ã®ã¯ã©ã¹ãå€æŽããå¿ èŠããããå€ãã®äºæããªãäœæ¥ãå¿ èŠã«ãªãå ŽåããããŸãã æãæãããªè§£æ±ºçã¯ããããã®ã¯ã©ã¹ã®ããããã®ã€ã³ã¿ãŒãã§ã€ã¹ãäœæããäŸåæ§æ³šå ¥ã䜿çšããããšã§ãã
äŸå€ ïŒãã¡ã€ã³é§åèšèšã§äœ¿çšããããã¡ã€ã³ã¢ãã«ã¯ãå®éã®é¢é£ä»ããèšè¿°ããåæ¹åã®äŸåé¢ä¿ã䜿çšããå ŽåããããŸãã ãã®ãããªå Žåãç§ã¯ããããæ¬åœã«å¿ èŠã§ããããšã確èªããããšããå¯èœãªéãããããé¿ããããšããŸãã
AV1025ã¯ã©ã¹ã«ã¯ç¶æ ãšåäœãå¿ èŠã§ã
ãªããžããªã«ããŒã¿ã®èª¬æã«ã®ã¿äœ¿çšãããå€ãã®ã¯ã©ã¹ãå«ãŸããŠããå Žåããã®ããŒã¿ãåŠçããããã®ããžãã¯ãå€æ°å«ãã¯ã©ã¹ïŒéçïŒãååšããå¯èœæ§ãé«ãïŒã«ãŒã«AV1008ãåç §ïŒã ãã®ã»ã¯ã·ã§ã³ã®æšå¥šäºé ã«åŸã£ãŠãªããžã§ã¯ãæåããã°ã©ãã³ã°ã®ååã䜿çšããããŒã¿åŠçããžãã¯ã䜿çšããããŒã¿ã«ç§»åããŸãã
äŸå€ ïŒãã®ã«ãŒã«ã®å¯äžã®äŸå€ã¯ã ããŒã¿è»¢éãªããžã§ã¯ããšãåŒã°ããã¢ããªã±ãŒã·ã§ã³ãµãã·ã¹ãã éã§ããŒã¿ã転éããããã«äœ¿çšãããã¯ã©ã¹ããŸãã¯ã¡ãœãããã©ã¡ãŒã¿ãŒã®ã©ãããŒãšããŠæ©èœããã¯ã©ã¹ã§ãã
ã¯ã©ã¹ã¡ã³ããŒã®èšèšã¬ã€ãã©ã€ã³
AV1100ã¯ã©ã¹ããããã£ã¯ä»»æã®é åºã§èšå®ã§ããå¿ èŠããããŸã
ããããã£ã¯ä»ã®ããããã£ã«äŸåããã¹ãã§ã¯ãããŸããã ã€ãŸããæåã«èšå®ããããããã£ã«éãã¯ãªãã¯ãã§ãã ããšãã°ãæåã«
DataSouse
ã次ã«
DataMember
ãŸãã¯ãã®éã§ãã
AV1105ããããã£ã®ä»£ããã«ã¡ãœããã䜿çšãã
次ã®å Žåãããããã£ã®ä»£ããã«ã¡ãœããã䜿çšããŸãã
- ãã£ãŒã«ãå€ãèšå®ãããããé«äŸ¡ãªäœæ¥ãè¡ãããŸã
- ããããã£ãã³ã³ããŒãžã§ã³ã®å Žåã ããšãã°ã
Object.ToString
ã¡ãœãã - åŒæ°ãå€æŽãããŠããªããŠããããããã£ãåŒã³åºãããšã«ç°ãªãå€ãè¿ãå Žåã ããšãã°ã
NewGuid
ã¡ãœããã¯æ¯åæ°ããå€ãè¿ããŸãã - ããããã£ã䜿çšãããšå¯äœçšãçºçããå Žåã ããšãã°ãããããã£ã«çŽæ¥é¢ä¿ããªãå éšç¶æ ã®å€æŽïŒããã¯ã ã³ãã³ãã¯ãšãªã®è²¬ä»»åé¢ïŒCQRSïŒã«éåããŸã ïŒ
äŸå€ ïŒå éšãã£ãã·ã¥ãåããããé 延èªã¿èŸŒã¿ãå®è£ ããããšã¯ããã®èŠåã®è¯ãäŸå€ã§ãã
AV1110çžäºã«æä»çãªããããã£ã䜿çšããªãã§ãã ãã
åæã«äœ¿çšã§ããªãããããã£ãããå Žåãããã¯ããããçžäºã«æä»çãª2ã€ã®æŠå¿µã§ããããšãæå³ããŸãã ãããã®æŠå¿µã«å ±éã®ããžãã¯ãšç¶æ ãå«ãŸããŠããå Žåã§ããããããäºãã«é©åããªãç°ãªãã«ãŒã«ãæã£ãŠããããšã¯æããã§ãã
ããããã£ãçžäºã«æä»çãªã«ãŒã«ãå«ããã¹ãŠã®çš®é¡ã®æ¡ä»¶ä»ãããžãã¯ãã«ãã»ã«åããå Žåããã®ã«ãŒã«ãžã®éåã¯ãã¡ã€ã³ã¢ãã«ã§ããèŠãããŸããããã¯ãã°ãã°æ³¢ã®å¹æãåŒãèµ·ããããã®ãããªã³ãŒãã®ç¶æã¯ããæéãããããŸãã
AV1115ã¡ãœãããŸãã¯ããããã£ã«ã¯åäžã®ç®çãå¿ èŠã§ãã
ãã¯ã©ã¹ïŒã«ãŒã«AV1000ãåç §ïŒãšåæ§ã«ãåã¡ãœããã«ã¯1ã€ã®è²¬ä»»é åãå¿ èŠã§ãã
AV1125éçã¡ã³ããŒãæã€ãªããžã§ã¯ããèšè¿°ããç¶æ ãå ¬éããªã
ã¹ããŒããã«ãªããžã§ã¯ãã¯ãå€ãã®ããããã£ãšãããã®ããããã£ãã«ãã»ã«åããããžãã¯ãå«ããªããžã§ã¯ãã§ãããã®ãããªãªããžã§ã¯ããéçããããã£ãŸãã¯å¥ã®ãªããžã§ã¯ãã®ã¡ãœãããä»ããŠå ¬éããå Žåãç¶æ ãæã€ãªããžã§ã¯ãã«äŸåããã¯ã©ã¹ããªãã¡ã¯ã¿ãªã³ã°ããã³åäœãã¹ãããããšã¯å°é£ã§ããäžè¬ã«ãäžèšã®èšèšã®äœ¿çšã¯ããã®ç« ã§èª¬æããå€ãã®æšå¥šäºé ã«éåãã奜äŸã§ãã
å žåçãªäŸã¯ã
HttpContext.Current
ASP.NETã®ããããã£ã§ããå€ãã®äººã ã¯ããã®ã¯ã©ã¹
HttpContext
ãå€ãã®æ±ãã³ãŒãã®ãœãŒã¹ãšèŠãªããŠããŸããå®éããã¹ãã«ãŒã«ã®1ã€-lyããã®ãåé¢ïŒïŒããã®ãåé¢ïŒ-ãã®ã¯ã©ã¹ã«å±ããããšããããããŸãã
AV1130 Return
IEnumerable
ãŸãã¯
ICollection
ç¹å®ã®ã³ã¬ã¯ã·ã§ã³ã§
ã¯ãªãããŠãŒã¶ãŒãã³ã¬ã¯ã·ã§ã³ãå€æŽã§ããªãããã«ããå Žåã¯ãé åãã·ãŒãããŸãã¯ãã®ä»ã®ã³ã¬ã¯ã·ã§ã³ã¯ã©ã¹ãçŽæ¥è¿ããªãã§ãã ããããã®ä»£ãããè¿ã
IEnumerable
ããŸãã¯ãŠãŒã¶ãŒã¯ãã³ã¬ã¯ã·ã§ã³å ã®èŠçŽ ã®æ°ãç¥ãå¿ èŠãããå Žå
ICollection
ã
泚ïŒ.Net 4.5ã䜿çšããå Žåã¯
IReadOnlyCollection
ã
IReadOnlyList
ãŸãã¯ã䜿çšããããšãã§ããŸã
IReadOnlyDictionary<TKey, TValue>
ã
AV1135ã®ããããã£ãã¡ãœããããŸãã¯è¡ãŸãã¯ã³ã¬ã¯ã·ã§ã³ãè¡šãåŒæ°ãçãããªãããšã¯ãããŸãã
null
æ»ããŸã
null
ãã®ã¡ãœããã®çµæãšããŠããŠãŒã¶ãŒã«ãšã£ãŠã¯é©ããããããŸããã nullåç §ã®ä»£ããã«ãåžžã«ç©ºã®ã³ã¬ã¯ã·ã§ã³ãŸãã¯ç©ºã®æååãè¿ããŸãã
null
ããã«ãã䜿çšããããããã«æªãããšã«ã䜿çšãããããããšã§ã³ãŒããè©°ãŸãããåé¡ãåé¿ã§ããŸã
string.IsNullOrEmpty()
ã
AV1137å¯èœãªéãç¹å®ã®ãã©ã¡ãŒã¿ãŒãå®çŸ©
ããã¯ã©ã¹èŠçŽ ãå¥ã®ã¯ã©ã¹ã®ããŒã¿ããã©ã¡ãŒã¿ãŒãšããŠå¿ èŠãšããå Žåããããã®ãã©ã¡ãŒã¿ãŒã®ããŒã¿åãå¯èœãªéãç¹å®ãããªããžã§ã¯ãå šäœããã©ã¡ãŒã¿ãŒãšããŠåãåããªãã§ãã ãããããšãã°ãäžå€®ã€ã³ã¿ãŒãã§ã€ã¹ã«èšè¿°ãããæ¥ç¶æååããã©ã¡ãŒã¿ãŒãšããŠæž¡ãå¿ èŠãããæ¹æ³ãèããŸã
IConfiguration
ããã®ã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ãããªããžã§ã¯ãå šäœããã©ã¡ãŒã¿ãŒãšããŠäœ¿çšãã代ããã«ãæ¥ç¶æååã®ã¿ãæž¡ããŸããããã«ãããã³ãŒãå ã®äŸåé¢ä¿ã®æ°ãæžããããšãã§ããã ãã§ãªããé·æçã«èŠãå Žåã®ä¿å®æ§ãåäžããŸãã
AV1140ããªããã£ãã®ä»£ããã«ãµããžã§ã¯ããšãªã¢ã«åºæã®ã¿ã€ãã䜿çšããŸã
æååãæŽæ°ãå°æ°ã䜿çšããŠISBNïŒåœéæšæºå³æžçªå·ïŒãã¡ãŒã«ã¢ãã¬ã¹ãéé¡ãªã©ã®ç¹å®ã®ã¿ã€ããè¡šã代ããã«ãããŒã¿èªäœãšæ€èšŒã«ãŒã«ã®äž¡æ¹ãå«ãåã¿ã€ãã®ãªããžã§ã¯ããäœæãããããã«é©çšãããŸããããããããšã§ãåãããžãã¹ã«ãŒã«ã®è€æ°ã®å®è£ ãåé¿ã§ããŸããããã«ãããã³ãŒãã®ä¿å®æ§ãåäžãããã°ã®æ°ãæžå°ããŸãã
ããŸããŸãªèšèšã¬ã€ãã©ã€ã³
AV1200ã¹ããŒã¿ã¹ã¡ãã»ãŒãžãè¿ã代ããã«äŸå€ãçæ
ããŸããè¿ãããã¹ããŒã¿ã¹ã¡ãã»ãŒãžã䜿çšããŠãæäœãæ£åžžã«å®äºãããã©ãããå€æããã³ãŒãããŒã¹
if
ãå€ãã®å ŽåããŠãŒã¶ãŒã¯æ»ãå€ã®ç¢ºèªãå¿ããŸããæ§é åäŸå€åŠçãå°å ¥ãããäŸå€ãã¹ããŒããŠãããé«ãã¬ãã«ã§äŸå€ããã£ãããŸãã¯çœ®æã§ããããã«ãªããŸãããã»ãšãã©ã®ã·ã¹ãã ã§ã¯ãäºæããªãç¶æ³ãçºçãããšãã«äŸå€ãã¹ããŒããããšã¯éåžžã«äžè¬çãªæ¹æ³ã§ãã
AV1202å®å šã§æå³ã®ããäŸå€ã¡ãã»ãŒãžãæäŸããŸã
ã¡ãã»ãŒãžã¯ãäŸå€ã®åå ã説æããå°æ¥ãããåé¿ããããã«äœãããå¿ èŠãããããæ確ã«èª¬æããå¿ èŠããããŸãã
AV1205å¯èœãªéãç¹å®ã®äŸå€ãçæããŸã
ããšãã°ãã¡ãœãããå ¥åãã©ã¡ãŒã¿ãŒãšããŠåãå ¥ããããå ŽåãããŒã¹ã¿ã€ãã®ä»£ããã«
null
çæããå¿ èŠããããŸããAV1210ã¯ãäžè¬çãªäŸå€ã¯åŠçããŠãšã©ãŒãç¡èŠããªããããªäžè¬çãªäŸå€ã¯ãåŠçããŠãšã©ãŒãç¡èŠããªããããã³ä»ã®ã¢ããªã±ãŒã·ã§ã³ã³ãŒãã§ããã¢ããªã±ãŒã·ã§ã³ããã°ã«èšé²ããŠæ£ããçµäºããããã«ããããã¬ãã«ã®ãšã©ãŒãã³ãã©ãŒã ããäžè¬çãªäŸå€ããã£ããããå¿ èŠããããŸããAV1215
ArgumentNullException
ArgumentException
Exception
SystemException
éåæã³ãŒãã®äŸå€ãé©åã«
åŠçãã
async/await
ãŸãã¯ã䜿çšããã³ãŒãã§äŸå€ãã¹ããŒãŸãã¯åŠçããå Žå
Task
ã次ã®2ã€ã®ã«ãŒã«ãèŠããŠãããŠãã ããã
- ãããã¯å
async/await
ããã³ãããã¯å ã§çºçããäŸå€Task
ã¯ããããã®ãããã¯ãå®äºããããšãæåŸ ããã¿ã¹ã¯ã«é©çšãããŸãã - åã«ã³ãŒãå
ã§çºçããäŸå€
async/await
ãšTask
ãçºä¿¡è ã«é©çšãããŸã
AV1220åžžã«
null
ããµãã¹ã¯ãªãã·ã§ã³ã®ãªãã€ãã³ãã®ã€ãã³ããã³ãã©ãŒããªã²ãŒãããã§ãã¯ã
null
ãŸãããããã£ãŠãåŒã³åºãããåã«ããã®ã€ãã³ããè¡šãããªã²ãŒãã®ãªã¹ããçãããªãããšã確èªããŠãã ãã
null
ããŸãã䞊åã¹ã¬ããããå€æŽãããšãã®ç«¶åãé¿ããããã«ãäžæå€æ°ã䜿çšããŠåæã«å€æŽããªãããã«ããŸãã
event EventHandler<NotifyEventArgs> Notify; void RaiseNotifyEvent(NotifyEventArgs args) { EventHandler<NotifyEventArgs> handlers = Notify; if (handlers != null) { handlers(this, args); } }
ãã³ãïŒããªã²ãŒããªã¹ããå®å šã«ç©ºã«ããªãããã«ããããšãã§ããŸãã以äžã«ç€ºãããã«ã空ã®ããªã²ãŒãã宣èšããã ãã§ãã
event EventHandler<NotifyEventArgs> Notify = delegate {};
AV1225ä¿è·ãããä»®æ³ã¡ãœããã䜿çšããŠåã€ãã³ããåŠçãã
ãã®æšå¥šäºé ã«åŸããšãä¿è·ãããã¡ãœããããªãŒããŒã©ã€ãããããšã«ããã掟çã¯ã©ã¹ãåºæ¬ã¯ã©ã¹ã€ãã³ããåŠçã§ããŸããä¿è·ãããä»®æ³ã¡ãœããã®ååã¯ãã€ãã³ãã®ååãšåãã§ããå¿ èŠããããŸããããã¬ãã£ãã¯ã¹ãä»ããŸã
On
ãããšãã°ãååãæã€ã€ãã³ãã®ä¿è·ãããä»®æ³ã¡ãœããã«ã¯ååãä»ãã
TimeChanged
å¿ èŠããããŸã
OnTimeChanged
ã
泚ïŒä¿è·ãããä»®æ³ã¡ãœããããªãŒããŒã©ã€ããã掟çã¯ã©ã¹ã¯ãåºæ¬ã¯ã©ã¹ã®å®è£ ãåŒã³åºãå¿ èŠã¯ãããŸãããåºæ¬ã¯ã©ã¹ã¯ããã®å®è£ ãåŒã³åºãããªããŠããåŒãç¶ãæ£åžžã«åäœããã¯ãã§ãã
AV1230ããããã£å€æŽéç¥ã€ãã³ãã®äœ¿çš
ããããã£å€æŽéç¥ã€ãã³ãã«ã¯ããã®ã€ãã³ããé¢é£ä»ããããŠããããããã£ã®ååã«å€æŽãã
PropertyChanged
å Žæã®ãããªååãä»ãã
Property
å¿ èŠããããŸãã
泚ïŒé©åãªã€ãã³ããå¿ èŠãšããå€ãã®ããããã£ãã¯ã©ã¹ã«ããå Žåã¯ã代ããã«ã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ããŠã¿ãŠãã ãã
INotifyPropertyChanged
ããã¬ãŒã³ããŒã·ã§ã³ã¢ãã«ããã³Model-View-ViewModelãã¿ãŒã³ã§ãã䜿çšãããŸãã
AV1235
null
ã€ãã³ããåŒã³åºããšãã«åŒæ°ãšããŠéä¿¡ããªãã§ãã ãã
å€ãã®å Žåãã€ãã³ããã³ãã©ã¯ãè€æ°ã®éä¿¡è ããã®åæ§ã®ã€ãã³ããåŠçããããã«äœ¿çšãããŸãããã®å Žåãæž¡ãããåŒæ°ã¯ã€ãã³ãåŒã³åºãã®ã³ã³ããã¹ããäŒããããã«äœ¿çšãããŸãã
this
ã€ãã³ããåŒã³åºããããšãã«ãåžžã«ã³ã³ããã¹ããžã®ãªã³ã¯ãïŒéåžžã¯ïŒéä¿¡ããŸãããŸãã
null
ããŒã¿ããªããšãã«ã€ãã³ãããã£ã¹ãããããªãã§ãã ãããã€ãã³ãã«ããŒã¿ããªãå Žåã¯ã
EventArgs.Empty
代ããã«éä¿¡ããŸã
null
ã
äŸå€ïŒéçã€ãã³ãã®å Žåãæž¡ãããåŒæ°ã¯ã§ãªããã°ãªããŸãã
null
ã
AV1240å¯èœãªå Žåã¯äžè¬çãªå¶éã䜿çš
ããåãç¹å®ã®åããäžè¬çãªåã«ãã£ã¹ãããã³å€æãã代ããã«ãããŒã¯ãŒã
where
ãŸãã¯æŒç®å
as
ã䜿çšããŠãªããžã§ã¯ããç¹å®ã®åã«ãã£ã¹ãããŸããäŸïŒ
class SomeClass {} // class MyClass<T> { void SomeMethod(T t) { object temp = t; SomeClass obj = (SomeClass) temp; } } // class MyClass<T> where T : SomeClass { void SomeMethod(T t) { SomeClass obj = t; } }
AV1250 LINQã¯ãšãªã®çµæãè¿ãåã«èšç®ãã
次ã®ã³ãŒããèŠãŠãã ããã
public IEnumerable<GoldMember> GetGoldMemberCustomers() { const decimal GoldMemberThresholdInEuro = 1000000; var q = from customer in db.Customers where customer.Balance > GoldMemberThresholdInEuro select new GoldMember(customer.Name, customer.Balance); return q; }
LINQã¯ãšãªã¯é 延å®è¡ã䜿çšãããã
q
ãå¥åŠãªããšã«returnã¯ãäžèšã®ã¯ãšãªãè¡šãåŒããªãŒãè¿ããŸãããŠãŒã¶ãŒãã
foreach
ãŸãã¯åæ§ã®ãã®ã䜿çšããŠçµæãèšç®ãããã³ã«ãã¯ãšãªå šäœãåå®è¡ãããæ¯åæ°ããã€ã³ã¹ã¿ã³ã¹ãäœæãããŸã
GoldMember
ããã®ãããæŒç®å
==
ã䜿çšããŠç°ãªãã€ã³ã¹ã¿ã³ã¹ãæ¯èŒããããšã¯ã§ããŸãã
GoldMember
ã代ããã«ãåžžã«æ瀺çã«èšç®çµæLINQ-èŠæ±ã䜿çš
ToList()
ã
ToArray()
ãŸãã¯åæ§ã®æ¹æ³ã
ã³ãŒãä¿å®ã®æ¹åã«é¢ããæšå¥šäºé
AV1500ã¡ãœããã«ã¯7ã€ä»¥äžã®å®£èš
ãå«ããããšã¯ã§ããŸããã7ã€ä»¥äžã®å®£èšãå«ãã¡ãœããã¯ãã»ãšãã©ã®å ŽåãããŸãã«ãå€ãã®è²¬ä»»ãè² ããŸããããã«ã人éã®èšæ¶ã«ã¯ã¡ãœãããçãããšãå¿ èŠã§ãã圌女ã¯ãç¹å®ã®ã³ãŒããäœãããããæ£ç¢ºã«åæããŠç解ããããã«ãããå€ãã®ãã®ãåæã«ä¿æããããšã¯ã§ããŸãããæ確ãªç®çãæã£ãŠã¡ãœãããããã€ãã®å°ããªã¡ãœããã«åå²ããå®è¡ããŠããããšãæ£ç¢ºã«ç€ºãååãä»ããŸããåæã«ãããã°ã©ã ã®ãã®éšåã®ã¢ã«ãŽãªãºã ãç解ã®ããã«æ確ãªãŸãŸã§ãããšããäºå®ã«æ³šæãæã£ãŠãã ããã
AV1501ã¯ã©ã¹ã®ãã¹ãŠã®ã¡ã³ããŒãäœæããããã©ã«ã
private
ã§ã¿ã€ã
internal
ããŸã
ã©ã®èŠçŽ ãä»ã®ã¯ã©ã¹ã§äœ¿çšå¯èœã«ãããã«ã€ããŠãããæ å ±ã«åºã¥ãã決å®ãè¡ãã«ã¯ããŸãããããã®ç¯å²ãå¯èœãªéãå¶éããŸãã次ã«ãå ¬éãã䟡å€ã®ããã¡ã³ããŒãŸãã¯ã¿ã€ããæ éã«æ€èšããŸãã
AV1502äºéåŠå®ãé¿ããïŒ
ããããã£ã«
customer.HasNoOrder
ã¯ååšããæš©å©ããããŸãããåŠå®ãšãšãã«äœ¿çšããããšã¯é¿ããŠãã ãããäŸïŒ
bool hasOrders = !customer.HasNoOrders;
äºéåŠå®ã¯åçŽãªè¡šçŸãããç解ãé£ããã人ã ã¯æ··ä¹±ããåŸåããããŸãã
AV1505ã®ãã®ã¿ã€ãã«ã«ã¢ã»ã³ããªåã¯ããã®åå空éã®ååã®åŸã«è¡ãã¹ã
ãã¹ãŠã®DLLã¯ããã¿ãŒã³ã«åŸã£ãŠååãä»ããå¿ èŠããã
Company.Component.dll
ã
Company
ããªãã®äŒç€Ÿã®ååã§ããããããŠ-
Component
-ååã®ããªãªãã§åºåããã1ã€ã®ä»¥äžã®ã¹ããŒã¹ãã®ååãäŸïŒ
AvivaSolutions.Web.Controls.dll
äŸã¯ã
AvivaSolutions.Web.Binding
ããçš®ã®ã¢ã»ã³ããªãå«ãåå空éå ã®ã¯ã©ã¹ã®ã°ã«ãŒãã®çµåã§ãããã®æšå¥šã«åŸã£ãŠããã®ã¢ã»ã³ããªã¯ãšããååã«ããå¿ èŠããããŸã
AvivaSolutions.Web.Binding.dll
ã
äŸå€ïŒç¡é¢ä¿ãªç°ãªãåå空éã®ã¯ã©ã¹ã1ã€ã®ã¢ã»ã³ããªã«ãªã³ã¯ããå Žåãååã«æ¥å°ŸèŸCoreãè¿œå ããŸãããã ããåå空éåã«ã¯ãã®æ¥å°ŸèŸã䜿çšããªãã§ãã ãããããšãã°ã次ã®ããã«
AvivaSolutions.Consulting.Core.dll
ã
AV1506ãã¡ã€ã«ã«å«ãŸããããŒã¿ã®çš®é¡ã«å¿ããŠãœãŒã¹ã³ãŒããã¡ã€ã«ã«
ååãä»ããŸããã¡ã€ã«ã«ååãä»ããã«ã¯ãã¹ã«ã«è¡šèšã䜿çšããã¢ã³ããŒã¹ã³ã¢ã¯äœ¿çšããŸããã
AV1507ãœãŒã¹ãã¡ã€ã«ã®ã³ã³ãã³ãã1ã€ã®ããŒã¿åã«å¶éãã
äŸå€ïŒãã¹ããããåã¯ãæãããªçç±ã«ãããåããã¡ã€ã«ã®äžéšã§ãªããã°ãªããŸããã
AV1508éšåããŒã¿åãå«ããœãŒã¹ã³ãŒããæã€ãã¡ã€ã«ã®ååã¯ããã®éšåã®ç®çãåæ ããå¿ èŠããããŸãã
éšååã䜿çšãããéšåããã¡ã€ã«ã«åå²ãããå Žåãåãã¡ã€ã«ã®ååã¯è«ççã«2ã€ã®éšåã«åå²ãããŸããæåã®éšåã¯ååã§ãã2çªç®ã¯ããã®ãã©ã°ã¡ã³ããã¿ã€ãã§æãã圹å²ã§ããäŸïŒ
// MyClass.cs public partial class MyClass {...} // MyClass.Designer.cs public partial class MyClass {...}
AV1510
using
å¥ã®ããŒã ã¹ããŒã¹ããã®åãžã®å®å šãªåç §ãæå®ãã代ããã«äœ¿çšã
ãŸãååã®ç«¶åãé²ãããã«ãå¥ã®ããŒã ã¹ããŒã¹ããã®åãžã®å®å šãªåç §ã䜿çšããªãã§ãã ãããããšãã°ããããããªãã§ãã ããïŒ
var list = new System.Collections.Generic.List<string>();
ãããè¡ãæ¹ãè¯ãã§ãïŒ
using System.Collections.Generic; var list = new List<string>();
ååã®ç«¶åãåé¿ããå¿ èŠãããå Žåã¯ããã£ã¬ã¯ãã£ã
using
ã䜿çšããŠåå空éã®ãšã€ãªã¢ã¹ãŸãã¯ã¿ã€ããäœæããŸãã
using Label = System.Web.UI.WebControls.Label;
AV1515ããžãã¯ãã³ããŒã䜿çšããªã
å®æ°ã宣èšãã以å€ã®ç®çã§ãã³ãŒãå ã§ãªãã©ã«å€ãæ°åããŸãã¯è¡ã䜿çšããªãã§ãã ãããäŸïŒ
public class Whatever { public static readonly Color PapayaWhip = new Color(0xFFEFD5); public cons tint MaxNumberOfWheels = 18; }
ãã®ã³ã°ãŸãã¯ãã¬ãŒã¹ãç®çãšããè¡ã¯ããã®èŠåã®äŸå€ã§ãããªãã©ã«å€ã¯ãã³ã³ããã¹ãããæå³ãæ確ã§ãå€æŽããäºå®ããªãå Žåã«ã®ã¿äœ¿çšã§ããŸããäŸïŒ
mean = (a + b) / 2; // WhaitMilliseconds(waitTimeInSeconds * 1000); //
ããå®æ°ã®å€ãå¥ã®å®æ°ã®å€ã«äŸåããå Žåã¯ãã³ãŒãã§ããã瀺ããŸãã
public class SomeSpecialContainer { public const int MaxItems = 32; public const int HighWaterMark = 3 * MaxItems / 4; // 75% }
泚ïŒå€ãã®å Žåãåæåã¯æåå®æ°ã®ãªããžããªãšããŠäœ¿çšã§ããŸãã
AV1520ã®äœ¿çšã¯ã
var
å€æ°ã®åãæãããªå Žåã«ã®ã¿
䜿çš
var
å€æ°ã¯ãLINQã¯ãšãªã®çµæãå²ãåœãŠãããŠããå Žåã«ã®ã¿ã¯ãå€æ°ã®åãæããã§ããå Žåãã䜿çšããã«ã¯
var
ãã³ãŒãã®å¯èªæ§ãåäžããŸããããšãã°ããããè¡ãã¹ãã§ã¯ãããŸããïŒ
var i = 3; // ? int? uint? float? var myfoo = MyFatoryMethod.Create(âargâ); // , // . , // , // c , //
代ããã«ã
var
次ã®äŸã®ããã«äœ¿çšããŸãã
var q = from order in orders where order.Items > 10 and order.TotalValue > 1000; var repository = new RepositoryFactory.Get<IOrderRepository>(); var list = new ReadOnlyCollection<string>();
3ã€ã®äŸãã¹ãŠã§ãå€æ°ã«å²ãåœãŠãããå€ã®ã¿ã€ãã¯æããã§ããvarã®äœ¿çšã®è©³çŽ°ã«ã€ããŠã¯ãEric Lippert ã®èšäºãæé»çãªåæå®ã®äœ¿çšãšæªçšããåç §ããŠãã ããã
AV1521ã§ããã ãé ãå€æ°ã宣èšããŠåæå
ãããã¹ãŠã®å€æ°ããããã¯ã®å é ã§å®£èšãããŠããå Žåã¯ãCããã³VisualBasicèšèªãé¿ããŠãã ãããå¿ èŠãªå Žåã«ã®ã¿ãåå€æ°ã宣èšããŠåæåããŸãã
AV1522åå¥ã®å®£èšã§åå€æ°ã®å€ãå²ãåœãŠãŸã
ã
var result = someField = GetSomeMethod();
AV1523
ãã®æ§ç¯ã®ä»£ããã«ãããããã£ã®åå¥ã®èšå®ããã³ã³ã¬ã¯ã·ã§ã³ãžã®æ°ãããªããžã§ã¯ãã®åå¥ã®è¿œå ãããããªããžã§ã¯ãããã³ã³ã¬ã¯ã·ã§ã³ã®åæååãåªå ããŸãã
var startInfo = new ProcessStartInfo(âmyapp.exeâ); startInfo.StandardOutput = Console.Output; startInfo.UseShellExecute = true;
ãªããžã§ã¯ãåæååã䜿çšããŸãã
var startInfo = new ProcessStartInfo(âmyapp.exeâ) { StandardOutput = Console.Output, UseShellExecute = true };
ã³ã¬ã¯ã·ã§ã³ãäœæãã代ããã«ã次ã®ããã«ããŸãã
var countries = new List<string>(); countries.Add(âNetherlandsâ); countries.Add(âUnited Statesâ);
ã³ã¬ã¯ã·ã§ã³åæååã䜿çšããŸãã
var countries = new List<string> { âNetherlandsâ, âUnited Statesâ };
AV1525 Doãã§æ瀺çãªæ¯èŒãè¡ãããšã§ã¯ãªã
true
ãã
false
è«çå€ãæ¯èŒãã
true
ããŸãã¯
false
ããã¯éåžžæªãããã°ã©ãã³ã°ã¹ã¿ã€ã«ã§ãããŸã- ãäŸãšããŠïŒ
while (condition == false) // , while (condition != true) // while (((condition == true) == true) == true) // ? while (condition) // OK
AV1530ã¯ãã«ãŒãå€æ°ãå€æŽããŠããªã
for
ãã
foreach
身äœã®ãµã€ã¯ã«å ã§
ã³ãŒããæ··ä¹±ããŠãããšããäºå®ã«äœãªãŒãã®ã«ãŒãå ã§ã«ãŒãå€æ°ãæŽæ°ããŸããç¹ã«ãå€æ°ãè€æ°ã®å Žæã§å€åããå Žåããã®èŠåã¯ã«ãŒãã«ãé©çšãããŸã
foreach
ããå埩ã®åŸãåæåã¯ã³ã¬ã¯ã·ã§ã³ã®å€æŽãæ€åºããäŸå€ãã¹ããŒããŸãã
for (int index = 0; index < 10; ++index) { if (some condition) { index = 11; // ! 'break' 'continue'. } }
AV1532ãã¹ããããã«ãŒããåé¿ãããã¹ããããã«ãŒã
ãå«ãã¡ãœããã¯ãã«ãŒãã1ã€ã ãå«ãã¡ãœãããããç解ãå°é£ã§ããå®éãã»ãšãã©ã®å Žåãã«ãŒãã¯ãããŒã¯ãŒãã
from
2å以äžäœ¿çšããŠããŒã¿ãçµåãããã¯ããã«å°ããªLINQã¯ãšãªã«çœ®ãæããããšãã§ããŸãã
AV1535å¿ ãå©çšèšèš
if
ã
else
ã
while
ã
for
ã
foreach
ããã³
case
ãã¬ãŒã¹ã¯ããš
ããããã«ãã¯ããã®ãããªæ§é ã§å¯èœãªæ··ä¹±ãé¿ããããã«ãªãããšã«æ³šæããŠãã ããïŒ
if (b1) if (b2) Foo(); else Bar(); // 'if' 'else'?
ãããè¡ãæ¹ãè¯ãã§ãïŒ
if (b1) { if (b2) { Foo(); } else { Bar(); } }
AV1536ã³ã³ã¹ãã©ã¯ãã®æåŸã«åžžã«ãããã¯
default
ã䜿çšããŸã
switch/case
ãããã¯
default
ã空ã®å Žåã¯ã説æã³ã¡ã³ããè¿œå ããŸããããã«ããã®ãããã¯ã«å°éã§ããªãå Žåã¯ãåŒã³åºã
InvalidOperationException
ãããšãã«çæããŠããããã¯ã«å°éããªãå°æ¥ã®å€æŽãæ€åºããŸã
case
ããã¹ãŠã®å®è¡ã¹ã¯ãªããã¯ãã§ã«èãåºãããŠããããããã®æšå¥šäºé ã«åŸããšãããã¯ãªãŒã³ãªã³ãŒããäœæã§ããŸãã
void Foo(string answer) { switch (answer) { case "no": Console.WriteLine("You answered with No"); break; case "yes": Console.WriteLine("You answered with Yes"); break; default: // Not supposed to end up here. throw new InvalidOperationException("Unexpected answer " + answer); } }
AV1537
if-else-if
åºåã§åãããã¯ãå®æãããŸã
else
äŸïŒ
void Foo(string answer) { if (answer == "no") { Console.WriteLine(" "); } else if (answer == "yes") { Console.WriteLine(" "); } else { // , ? ? // , InvalidOperationException. } }
AV1540è€æ°ã®ã¢ããŠã³ã¹ãé¿ããããã«ããŠãã ãã
return
1ã€ã®å ¥å-1ã€ã®åºå£ãã€ã³ãããã®ååã¯ãã®ããã«èãããŸããããã«ãããã¡ãœããã®é²è¡ç¶æ³ãæ確ã«ä¿ã€ããšãã§ããŸããããã«ãã¡ãœãããéåžžã«å°ãããAV1500ã®æšå¥šäºé ãæºãããŠãã
return
å Žåãããã€ãã®çºè¡šãé¢é£ããã³ãŒãã®èªã¿ããããåäžãããå¯èœæ§ããããŸããããšãã°ãã¡ãœãããè«çå€ãè¿ãå Žåãã¡ãœãããè¿ã
return
è«çå€æ°ã®ä»£ããã«ãå®è¡æã«å€ãå²ãåœãŠããã2ã€ã®å®£èšã䜿çšããã»ãã䟿å©ã§ãã
AV1545
if-else
åçŽãªïŒæ¡ä»¶ä»ãïŒå²ãåœãŠã®ä»£ããã«ãããã¯ã䜿çšããªãã§
ãã ããæå³ãçŽæ¥è¡šçŸããŠãã ãããããšãã°ã代ããã«ïŒ
bool pos; if (val > 0) { pos = true; } else { pos = false; }
ãããè¡ãïŒ
bool pos = (val > 0); //
代ããã«ïŒ
string result; if (someString != null) { result = someString; } else { result = âUnavailableâ; }
æžãïŒ
return someString ?? âUnavailableâ;
AV1547è€éãªåŒãã¡ãœãããŸãã¯ããããã£ã«ã«ãã»ã«åãã
次ã®äŸãèããŠã¿ãŸãããã
if (member.HidesBaseClassMember && (member.NodeType != NodeType.InstanceInitializer)) { // - }
ãã®ã³ãŒããäœãããããç解ããã«ã¯ããã®è©³çŽ°ãæãäžãããã®å®è¡ã®ãã¹ãŠã®ãªãã·ã§ã³ãäºæž¬ããå¿ èŠããããŸãããã¡ããããã®ã³ãŒãã®åã«èª¬æçšã®ã³ã¡ã³ããè¿œå ããããšãã§ããŸãããè€éãªåŒããååãè¡šãã¡ãœããã«çœ®ãæããæ¹ãè¯ãã§ãããã
if (NonConstructorMemberUsesNewKeyword(member)) { // - } private bool NonConstructorMemberUsesNewKeyword(Member member) { return (member.HidesBaseClassMember && (member.NodeType != NodeType.InstanceInitializer) }
ãã®ã¡ãœãããå€æŽããå¿ èŠãããå Žåããããã©ã®ããã«æ©èœããããç解ããå¿ èŠããããŸããããããä»ã§ã¯ããããåŒã³åºãã³ãŒããç解ããã®ãã¯ããã«ç°¡åã«ãªããŸããã
AV1551ä»ã®ãªãŒããŒããŒãããæããªãŒããŒããŒããããã¡ãœãããåŒã³åºã
ãã®ã«ãŒã«ã¯ããªãã·ã§ã³ã®åŒæ°ã§ãªãŒããŒããŒããããã¡ãœããã«ã®ã¿é©çšãããŸãã以äžã®äŸãèŠãŠãã ããã
public class MyString { private string someText; public MyString(string text) { this.someText = text; } public int IndexOf(string phrase) { return IndexOf(phrase, 0, someText.Length); } public int IndexOf(string phrase, int startIndex) { return IndexOf(phrase, startIndex, someText.Length - startIndex ); } public virtual int IndexOf(string phrase, int startIndex, int count) { return someText.IndexOf(phrase, startIndex, count); } }
ãã®ã¯ã©ã¹
MyString
ã¯3ã€ã®ã¡ãœãããªãŒããŒããŒããæäŸããŸãã
IndexOf
ããã®ãã¡2ã€ã¯åçŽã«å€æ°ã®ãã©ã¡ãŒã¿ãŒã§å¥ã®ã¡ãœãããåŒã³åºããŸãããã®èŠåã¯ã¯ã©ã¹ã³ã³ã¹ãã©ã¯ã¿ãŒã«é©çšãããããšã«æ³šæããŠãã ãããæããªãŒããŒããŒããããã³ã³ã¹ãã©ã¯ã¿ãŒãå®è£ ããæŒç®åã䜿çšããŠä»ã®ãªãŒããŒããŒãããåŒã³åºããŸã
this()
ããŸãããã¹ãŠã®ãªãŒããŒããŒãã§åãååã®ãã©ã¡ãŒã¿ãŒãåãé åºã§ç¶ãå¿ èŠãããããšã«æ³šæããŠãã ããã
éèŠïŒãããã®ã¡ãœããããªãŒããŒã©ã€ãããŠã¯ã©ã¹ã®åäœãå€æŽãããå Žåã¯ãæããªãŒããŒããŒããããã¡ãœããããšããŠå®£èšã
protected virtual
ãŸããããã¯ããã¹ãŠã®ãªãŒããŒããŒãã«ãã£ãŠåŒã³åºãããŸãã
AV1553ãªãŒããŒããŒãã眮ãæããå Žåã«ã®ã¿ãªãã·ã§ã³ã®åŒæ°ã䜿çšããŠãã ãã
ãªãã·ã§ã³ã®CïŒ4.0åŒæ°ã䜿çšããå¯äžã®æ£åœãªçç±ã¯ãã«ãŒã«AV1551ã®äŸã次ã®ãããªåäžã®ã¡ãœããã«çœ®ãæããããšã§ãã
public virtual int IndexOf(string phrase, int startIndex = 0, int count = 0) { return someText.IndexOf(phrase, startIndex, count); }
ãªãã·ã§ã³ã®ãã©ã¡ãŒã¿ãŒãåç §åã§ããå Žåãããã©ã«ãå€ã®ã¿ãæã€ããšãã§ããŸã
null
ããããããšç§ãã¡ã¯ç¥ã£ãŠãã
string
ã
list
ãš
collections
çãããªãããšã¯ãããŸãã
null
ïŒèŠåAV1135ã«ãããŸãïŒããããã£ãŠã代ããã«ãªãŒããŒããŒããããã¡ãœããã䜿çšããå¿ èŠããããŸãã
泚ïŒã³ã³ãã€ã©ãŒã¯ããªãã·ã§ã³ã®ãã©ã¡ãŒã¿ãŒã®å€ãåŒã³åºãå Žæã«ã³ããŒããŸãããããã£ãŠããªãã·ã§ã³ã®ãã©ã¡ãŒã¿ãŒã®ããã©ã«ãå€ã®å€æŽã«ã¯ãåŒã³åºãã³ãŒãã®åã³ã³ãã€ã«ãå¿ èŠã§ãã
泚ïŒã€ã³ã¿ãŒãã§ãŒã¹ã¡ãœããããªãã·ã§ã³ã®ãã©ã¡ãŒã¿ãŒãå®çŸ©ããå Žåãã€ã³ã¿ãŒãã§ãŒã¹ãä»ããŠãã®ã¡ââãœããã®å®è£ ãåŒã³åºããŸã§ããªãŒããŒããŒãã®è§£æ±ºäžã«ãã®ããã©ã«ãå€ã¯èæ ®ãããŸãããèšäºãèŠã詳现ã«ã€ããŠã¯ããšãªãã¯ã»ãªãããŒãã
AV1555
ååä»ãåŒæ°ã®äœ¿çšãé¿ããCïŒ4.0ã®ååä»ãåŒæ°ã¯ãå€æ°ã®ãªãã·ã§ã³ãã©ã¡ãŒã¿ãæäŸããããšãç¥ãããŠããCOMã³ã³ããŒãã³ãã®åŒã³åºãã容æã«ããããã«äœæãããŸãããã¡ãœããã®åŒã³åºãã®èªã¿ããããåäžãããããã«ååä»ãåŒæ°ãå¿ èŠãªå Žåããã®ã¡ãœããã¯å€ãããããããªãã¡ã¯ã¿ãªã³ã°ããå¿ èŠããããŸãã
次ã®äŸã®ããã«ãååä»ãåŒæ°ãèªã¿ããããåäžãããå¯äžã®äŸå€ã¯ããªããžã§ã¯ãã®ã³ã³ã¹ãã©ã¯ã¿ãŒãåŒã³åºãããå Žåã§ãã
Person person = new Person ( firstName: "John", lastName: "Smith", dateOfBirth: new DateTime(1970, 1, 1) );
AV1561ã¡ãœãããŸãã¯ã³ã³ã¹ãã©ã¯ã¿ãŒã3ã€ä»¥äžã®ãã©ã¡ãŒã¿ãŒãåãå ¥ããããšãèš±å¯ããªãã¡ãœãããŸãã¯ã³ã³ã¹ãã©ã¯ã¿ãŒã4ã€ä»¥äžã®ãã©ã¡ãŒã¿ãŒãåãå ¥ãã
å Žåãæ§é ãŸãã¯ã¯ã©ã¹ã䜿çšããŠããã¿ãŒã³ä»æ§ã«åŸã£ãŠããããã«ãã»ã«åããŸããäžè¬ã«ããã©ã¡ãŒã¿ãŒã®æ°ãå°ãªãã»ã©ãã¡ãœãããç解ãããããªããŸããããã«ãå€ãã®ãã©ã¡ãŒã¿ãŒãæã€ã¡ãœããã®åäœãã¹ãã«ã¯ããã¹ãã®ããã®å€ãã®ã·ããªãªãå¿ èŠã§ãã
AV1562䜿çšããªã
ref
ãšã
out
ãã©ã¡ãŒã¿
圌ãã¯ã³ãŒããããŸãæ確ã«ããŠããšã©ãŒã®ããã®åææ¡ä»¶ãäœæããŸãã代ããã«ãé¢æ°ã®çµæãšããŠè€åãªããžã§ã¯ããè¿ããŸãã
AV1564ãã©ã¡ãŒã¿ãŒãšããŠããŒã«å€ããšãã¡ãœãããäœæããªãã§ãã ãã
次ã®æ¹æ³ãèŠãŠãã ããã
public Customer CreateCustomer(bool platinumLevel) {}
äžèŠããã¹ãŠãçŽ æŽãããèŠããŸããããã®æ¹æ³ã䜿çšãããšãè«çå€æ°ã®æå³ãå®å šã«ãããã«ãããªããŸãã
Customer customer = CreateCustomer(true);
éåžžãã¡ãœããããã©ã¡ãŒã¿ãŒãšããŠããŒã«å€ãã©ã°ãåãå ¥ããå Žåããã®ã¡ãœããã¯è€æ°ã®ããšãè¡ãã2ã€ä»¥äžã®ã¡ãœããã«åå²ããã«ã¯ãªãã¡ã¯ã¿ãªã³ã°ãå¿ èŠã§ããå¥ã®è§£æ±ºçã¯ããã©ã°ãåæã«çœ®ãæããããšã§ãã
AV1568ãã©ã¡ãŒã¿ãŒãäžæå€æ°ãšããŠäœ¿çšãã
ããã©ã¡ãŒã¿ãŒãå éšå€æ°ãšããŠäœ¿çšããªãã§ãã ããããã©ã¡ãŒã¿ãŒã®ã¿ã€ããå¿ èŠãªã¿ã€ããšäžèŽããå Žåã§ããååã¯ãéåžžãäžæå€æ°ã®ç®çãåæ ããŸããã
AV1570åžžã«ãªãã¬ãŒã¿ãŒã«ãã£ãŠè¿ãããçµæã確èªã
as
ãŸãããªãã¬ãŒã¿ãŒ
as
ã䜿çšããŠãªããžã§ã¯ããç¹å®ã®ã€ã³ã¿ãŒãã§ã€ã¹ã«ç§»åããå Žåã¯ãåžžã«ããã«ãã£ãŠè¿ãããçµæã確èªããŸã
null
ããã
NullReferenceException
ããªããšããªããžã§ã¯ããå¿ èŠãªã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ããŠããªãå Žåãããã°ã©ã å®è¡ã®ããªãåŸã®æ®µéã§é€å€ãããå¯èœæ§ããããŸãã
AV1575ã³ã¡ã³ãä»ãã®ã³ãŒãã»ã¯ã·ã§ã³ãæ®ããªãã§ãã ããã
ã³ã¡ã³ãä»ãã®ã³ãŒãããªããžããªã«éä¿¡ããªãã§ãã ããã代ããã«ãã¿ã¹ã¯è¿œè·¡ã·ã¹ãã ã䜿çšããŠãå®è¡ããå¿ èŠãããäœæ¥ã远跡ããŸãããã®åŸãã³ã¡ã³ãä»ãã³ãŒãã®ãã®ãããã¯ãŸãã¯ãã®ãããã¯ãäœã®ããã«ããã®ãã誰ãæšæž¬ããŸããããã¹ãã®ããã«äžæçã«ã³ã¡ã³ãã¢ãŠããããŸãããïŒäŸãšããŠã³ããŒãããŸãããïŒåé€ããå¿ èŠããããŸããïŒ
åœåã¬ã€ãã©ã€ã³
AV1701ã¢ã¡ãªã«è±èªã䜿çšïŒ
ãã¹ãŠã®ã¯ã©ã¹ã¡ã³ããŒããã©ã¡ãŒã¿ãŒãããã³å€æ°ã«ã¯ãã¢ã¡ãªã«è±èªã®åèªã䜿çšããŠååãä»ããå¿ èŠããããŸãã
- ç°¡åã§èªã¿ããããã§ããã°ææ³çã«æ£ããååãéžæããŠãã ãããããšãã°ã
HorizontalAlignment
ããèªã¿ãããååAlignmentHorizontal
- ç°¡æœãããèªã¿ããããåªå
ããŸããããããã£åã®
CanScrollHorizontally
æ¹ãåªããŠããŸãScrollableX
ïŒX軞ãåç §ããŠãäœãèšãããŸããïŒ - ããã°ã©ãã³ã°èšèªã®ããŒã¯ãŒããšç«¶åããååã®äœ¿çšãé¿ãã
äŸå€ïŒã»ãšãã©ã®ãããžã§ã¯ãã§ã¯ããã®ã¢ããªã±ãŒã·ã§ã³åºæã®ãµããžã§ã¯ããšãªã¢ã®åèªããã¬ãŒãºãããã³äŒç€Ÿåºæã®ååã䜿çšã§ããŸããVisual Studioã®éçã³ãŒãã¢ãã©ã€ã¶ãŒã¯ã³ãŒãå šäœãåæããããããããã®çšèªãã«ã¹ã¿ã ã³ãŒãåæèŸæžã«è¿œå ããå¿ èŠãããå ŽåããããŸãã
AV1702åèšèªèŠçŽ ã«åè¡šèšæ³ã䜿çšããŸãã
èšèªèŠçŽ | è¡šèšæ³ | äŸ |
---|---|---|
ã¯ã©ã¹æ§é | ãã¹ã«ã« | AppDomain
|
ã€ã³ã¿ãŒãã§ãŒã¹ | ãã¹ã«ã« | IBusinessService
|
åæïŒã¿ã€ãïŒ | ãã¹ã«ã« | ErrorLevel
|
åæïŒå€ïŒ | ãã¹ã«ã« | FatalError
|
ã€ãã³ã | ãã¹ã«ã« | Click
|
ãã©ã€ããŒããã£ãŒã«ã | ã©ã¯ãèšæ³ | listItem
|
ä¿è·ãã£ãŒã«ã | ãã¹ã«ã« | MainPanel
|
å®æ°ãã£ãŒã«ã | ãã¹ã«ã« | MaximumItems
|
å®æ°ããŒã«ã«å€æ° | ã©ã¯ãèšæ³ | maximumItems
|
èªã¿åãå°çšã®éçãã£ãŒã«ã | ãã¹ã«ã« | RedValue
|
å¯å€ | ã©ã¯ãèšæ³ | listOfValues
|
æ¹æ³ | ãã¹ã«ã« | ToString
|
åå空é | ãã¹ã«ã« | System.Drawing
|
ãã©ã¡ãŒã¿ | ã©ã¯ãèšæ³ | typeName
|
åãã©ã¡ãŒã¿ãŒ | ãã¹ã«ã« | TView
|
ç©ä»¶ | ãã¹ã«ã« | BackColor
|
AV1704å€æ°ããã©ã¡ãŒã¿ãããã³ã¿ã€ãã®ååã«æ°åãå«ããªãã§ãã ãã
ã»ãšãã©ã®å Žåãæ inessã ããæ確ã§èªæã®ååã®æ¬ åŠãåŒãèµ·ãããŸãã
AV1705ãã£ãŒã«ãåã«ãã¬ãã£ãã¯ã¹ã䜿çšããªãã§ãã ãã
ãããšãã°ãéçãã£ãŒã«ããšééçãã£ãŒã«ãã䜿çšã
g_
ãã
s_
ãåºå¥ãããããªãã§ãã ãããéåžžãã¡ãœããã§ããŒã«ã«å€æ°ãšã¯ã©ã¹ãã£ãŒã«ããåºå¥ããããšãå°é£ãªå Žåããã®ã¡ãœããã¯é¢åã§ããããã§ã¯ã誀ã£ãååã®ããã€ãã®äŸããããŸãïŒ
_currentUser
ã
mUserName
ã
m_loginTime
ã
AV1706ç¥èªã䜿çšããªãã§ãã ãã
ãããšãã°ã
OnButtonClick
代ããã«äœ¿çšããŠãã ãã
OnBtnClick
ããiãããqããªã©ã®å€æ°åã«åäžã®æåã䜿çšããªãã§ãã ããã代ããã«ããindexãããqueryããªã©ã®å®å šãªåèªã䜿çšããŠãã ããã
äŸå€ïŒãµããžã§ã¯ããšãªã¢ã§ããç¥ãããŠããç¥èªãŸãã¯äžè¬ã«åãå ¥ããããŠããç¥èªã®äœ¿çšã¯ããã®èŠåã®äŸå€ã§ããå ŽåããããŸããããšãã°ã
UI
代ããã«äœ¿çšããŸã
UserInterface
ã
AV1707åã§ã¯ãªããç®çã«å¿ããŠã¯ã©ã¹ã¡ã³ããŒããã©ã¡ãŒã¿ãŒãå€æ°ã«ååãä»ããŸã
- ã¯ã©ã¹ã®ã¡ã³ããŒãå®è¡ããæ©èœã瀺ãååã䜿çšããŸããããšãã°ãååã®
GetLength
æ¹ãåªããŠããŸããGetInt
Enum
ãClass
ãŸãã¯Struct
ååãªã©ã®çšèªã䜿çšããªãã§ãã ãã- ã³ã¬ã¯ã·ã§ã³åç §å€æ°ã«ã¯è€æ°åãå¿ èŠã§ã
AV1708åè©ãŸãã¯åœ¢å®¹è©ããã®ãã¬ãŒãºã䜿çšããååã®ã¿ã€ã
æªãäŸïŒïŒ
SearchExamination
ãã¹ãçµæãæ€çŽ¢ããããŒãžïŒã
Common
ïŒæåŸã«åè©ã¯ãããŸãããååã¯ç®çã説æããŠããŸããïŒãããã³
SiteSecurity
ïŒæè¡çãªèŠ³ç¹ããã¯ãã¹ãŠåé¡ãããŸããããååã¯ç®çã«ã€ããŠäœãèšã£ãŠããŸããïŒè¯ãäŸã¯ä»¥äžã®éãã§ã
BusinessBinder
ã
SmartTextBox
ãš
EditableSingleCustomer
ã
ã¯ã©ã¹å
Utility
ããªã©ã®çšèªãå«ããªãã§ãã ãã
Helper
ããã®ãããªååã®ã¯ã©ã¹ã¯éåžžéçã§ããããªããžã§ã¯ãæåããã°ã©ãã³ã°ã®ååãèæ ®ããã«èšèšãããŠããŸãïŒã«ãŒã«AV1008ãåç §ïŒã
AV1709ãžã§ããªãã¯åãã©ã¡ãŒã¿ãŒã«ååãä»ãããšãã¯ãããããããååã䜿çšããŠãã ãã
- åãã©ã¡ãŒã¿ã®èª¬æçãªååã«ã¯åžžã«æ¥é èŸãTããè¿œå ããŸã
- 説æãªãã§1æåã®ååãå®å šã«ç解ãããªãéããåžžã«èª¬æçãªååã䜿çšããŠãã ããããã®å Žåãåãã©ã¡ãŒã¿ãŒã®ååãšããŠæåãTãã䜿çšããŸã
- åãã©ã¡ãŒã¿ãŒåã«ã¯ãåãã©ã¡ãŒã¿ãŒã«èª²ããããå¶éãå«ããããšããå§ãããŸããããšãã°ãå°çšã®ãã©ã¡ãŒã¿ã
ISession
åŒã³åºãããšãã§ããŸãTSession
AV1710ã¯ã©ã¹åãŸãã¯ã¡ã³ããŒåã®ãªã¹ããç¹°ãè¿ããªãã§ãã ãã
class Employee { // ! static GetEmployee() {} DeleteEmployee() {} // static Get() {...} Delete() {...} // . AddNewJob() {...} RegisterForMeeting() {...} }
AV1711èŠçŽ ã«ãé¢é£ãã.NET Frameworkã¯ã©ã¹ã®èŠçŽ ã«é¡äŒŒããååãä»ããŸã.NET
éçºè ã¯ã.NET Frameworkã§äœ¿çšãããŠããåœåãã¿ãŒã³ã«æ¢ã«æ £ããŠããŸãããããã£ãŠããããã®ãã¿ãŒã³ã«åŸãããšã¯ãã³ãŒããããéãç解ããã®ã«åœ¹ç«ã¡ãŸããããšãã°ãããªããã¯ã©ã¹ãå®çŸ©ããå Žåããã®å®è£ ã®ã³ã¬ã¯ã·ã§ã³ãååã®é€å»æ¹æ³ã®èŠçŽ ããã®è£œé æ¹æ³ãªã©ã®èŠçŽ åã®æ°ãå ç®ã
Add
ã
Remove
ãããŠ
Count
代ããã®
AddItem
ã
Delete
ãŸãã¯
NumberOfItems
ã
AV1712çãååãŸãã¯ä»ã®ååãšæ··åãããå¯èœæ§ã®ããååã¯é¿ããŠãã ãã
æè¡çãªèŠ³ç¹ããã¯ã次ã®åŒã¯æ£ããããã«èŠãããããããŸããããããã«ééãã人ãç°¡åã«èª€è§£ãããå¯èœæ§ããããŸã
bool b001 = (lo == l0) ? (I1 == 11) : (lOl != 101);
AV1715ããããã£ã«é©åãªååãä»ããã®ãæ ããªãã§ãã ãã
- åè©ãåè©ãå«ããã¬ãŒãºããŸãã¯æ¥µç«¯ãªå Žåã«ã¯åœ¢å®¹è©ãå«ããã¬ãŒãºã䜿çšããŠãããããã£ã«ååãä»ããŸã
- è¯å®çãªãã¬ãŒãºã䜿çšããŠãè«çã¿ã€ããæã€ããããã£ã«ååãä»ããŸããããšãã°ã
CanSeek
代ããã«CantSeek
- è«çåãæã€ããããã£ã®ååãæ¥é èŸã䜿çšããŠã¿ãŠãã ãã
Is
ãHas
ãCan
ãAllows
ãŸãã¯Support
- ããããã£ã«ãã®ã¿ã€ããšåãååãä»ããŠã¿ãŠãã ãããåæåãæã€ããããã£ãäœæããå Žåãããããã£ã®ååã¯åæåã®ååãšåãã«ãªãå ŽåããããŸããããšãã°ãåæåãããå Žå
CacheLevel
ãå€ã®1ã€ãè¿ãããããã£ã«ã¯ååãå¿ èŠã§ããCacheLevel
AV1720åè©ãšãªããžã§ã¯ãã®æ¥ç¶è©ã䜿çšããååã¡ãœããåè©ãšãªããžã§ã¯ãã®
æ¥ç¶è©ã䜿çšããååã¡ãœããè¯ãäŸããã
ShowDialog
ãŸããé©åãªååã¯ããã®ã¡ãœãããäœãããã®ããå¯èœã§ããã°ãã®çç±ã瀺ããã³ãã«ãªãã¯ãã§ãããŸã
And
ãã¡ãœããã®ååã«ãã®åèªã䜿çšããªãã§ãã ãããããã¯ãã¡ãœãããè€æ°ã®ããšãè¡ãããšã瀺åããŠããŸããããã¯ãåäžè²¬ä»»ã®ååïŒAV1115ïŒã®éåã§ãã
AV1725ååã®ååã«ã¯ãé©åãªååãã¢ãžã¥ãŒã«ïŒã¬ã€ã€ãŒïŒã®ååãç¹å®ã®åå空éã®ç¹åŸŽã説æããåè©ãšåèªã䜿çšããŸãã
ããšãã°ã次ã®åå空éã®ååã¯è¯ãäŸã§ãã
AvivaSolutions.Commerce.Web NHibernate.Extensibility Microsoft.ServiceModel.WebApi Microsoft.VisualStudio.Debugging FluentAssertion.Primitives CaliburnMicro.Extensions
泚ïŒåå空éã«ååãå«ããããšã¯çµ¶å¯Ÿã«èš±å¯ããªãã§ãã ããããã ããããšãã°
Collections
ãè€æ°åœ¢ã®åè©ã§ããå Žåãããã¯éåžžæå¹ã§ãã
AV1735ã€ãã³ãåã«åè©ãå«ãåè©ãŸãã¯ãã¬ãŒãºã䜿çšããåè©ãŸãã¯åè©ãå«ããã¬ãŒãºã§ã€ãã³ãã«ååã
ä»ããŸããããšãã°ã次ã®ããã«
Click
ã
Deleted
ã
Closing
ã
Minimizing
ããš
Arriving
ãã€ãã³ãã®ãç¥ãã
Search
ã¯æ¬¡ã®ããã«ãªããŸãã
public event EventHandler<SearchArgs> Search;
AV1737ã®äœ¿çš
âing
ã
âed
ä»ã®ã€ãã³ãã®åãšåŸã«èµ·ãã£ãã€ãã³ãã®ããã«ã¯
ãäŸãã°ãçªã®ééã®åã«ã€ãã³ãã¯ãåŒã°ããã¹ã
Closing
ããšãã®ééåŸã«çºçããã€ãã³ã-
Closed
ãæ¥é èŸã䜿çšããªãã§ãã ãã
Before
ãš
After
ããããã®ã€ãã³ããèå¥ããããã«ããŸãã¯ããããã®æ¥å°ŸèŸãã
ãªããžã§ã¯ããåé€ããããã»ã¹ã«é¢é£ããã€ãã³ããç¹å®ãããšããŸããã€ãã³ãã®ååä»ã
Deleting
ãšã
Deleted
ãããã®ãããªååãé¿ãã
BeginDelete
ãš
EndDelete
ã次ã®ããã«ã€ãã³ãã«ååãä»ããŸãã
-
Deleting
ïŒãªããžã§ã¯ããåé€ããçŽåã«çºçããŸã -
Delete
ïŒã€ãã³ããã³ãã©ãŒã«ãã£ãŠãªããžã§ã¯ããåé€ããå¿ èŠãããå Žåã«çºçããŸãã -
Deleted
ïŒãªããžã§ã¯ããæ¢ã«åé€ãããŠããå Žåã«çºçããŸãã
AV1738
On
ã€ãã³ããã³ãã©ã®ååã«ãã¬ãã£ãã¯ã¹ã䜿çšããã€ãã³ããåŠçããã¡ãœããã®ååã«
ãã¬ãã£ãã¯ã¹
On
ãè¿œå ããããšããå§ãããŸããããšãã°ãã¡ãœãããã€ãã³ããåŠçããå Žå
Closing
ãååã¯ã§ããå¿ èŠããããŸã
OnClosing
ã
AV1739é¢ä¿ã®ãªãã©ã ãåŒã®ãã©ã¡ãŒã¿ãŒã«ã¯ã¢ã³ããŒã¹ã³ã¢æåã䜿çšããŸãã
ããšãã°ãã€ãã³ãããµãã¹ã¯ã©ã€ãããããã«ã©ã ãåŒã䜿çšããã€ãã³ãã®çŸåšã®ãã©ã¡ãŒã¿ãŒã¯é¢ä¿ãªãå Žåã¯ã次ã®èŠåã䜿çšããŠãããããå ·äœçã«ç€ºããŸãã
button.Click += (_, __) => HandleClick();
AV1745ãµãã£ãã¯ã¹ã䜿çšããŠãã¯ã©ã¹å ã®æ¡åŒµã¡ãœããã°ã«ãŒãã«
Extentions
ååãä»ããŸãæ¡åŒµã¡ãœããã®ååãå¥ã®èŠçŽ ãŸãã¯æ¡åŒµã¡ãœãããšç«¶åããå Žåãã¯ã©ã¹åã®ãã¬ãã£ãã¯ã¹ãåŒã³åºãã«è¿œå ããå¿ èŠããããŸããæ¥å°ŸèŸãä»ããŠé¢é£ããã¯ã©ã¹ã«è¿œå ãããšã
Extensions
èªã¿ããããªããŸãã
AV1755ãµãã£ãã¯ã¹ãè¿œå ãã
Async
ã
TaskAsync
ãéåæã¡ãœããã®ååã«
æ»ãè¿ãããã¡ãœããã®äžè¬çãªæšå¥šäºé
Task
ã¯ããµãã£ãã¯ã¹ãè¿œå ããããš
Async
ã§ãããã ãããã®ååã®ã¡ãœãããæ¢ã«ååšããå Žåã¯ã代ããã«ãµãã£ãã¯ã¹ã䜿çšããŸã
TaskAsync
ã
ããã©ãŒãã³ã¹ã®æšå¥šäºé
AV1800ã¡ãœããã䜿çš
Any()
ã
IEnbmerable
ãŠç©ºã確èª
ããã¡ãœãããŸãã¯ä»ã®ã¢ã€ãã ãè¿ããã
IEnumerable
ããããããã£ãæäŸããªãå¥ã®ã³ã¬ã¯ã·ã§ã³ã¯ã©ã¹ã®
Count
å Žåã
Any()
代ãã
Count()
ã«æ¡åŒµã¡ãœããã䜿çšããŠã³ã¬ã¯ã·ã§ã³ã®ç©ºã確èªããŸããã䜿çšãããš
Count()
ãçç£æ§ãäœäžãããªã¹ã¯ããããŸãããªããªããããã«ãããã³ã¬ã¯ã·ã§ã³å šäœã®å埩ãçºçããŸãïŒããšãã°ã
IQueryable
ããŒã¿èŠæ±ãå®è¡ãããå ŽåïŒã
泚ïŒ
IEnumerable
AV1130ã«ãŒã«ã§æšå¥šãããŠããããã«æ»ãã³ã¬ã¯ã·ã§ã³ãå€æŽãããªãããã«æ»ãã.NET 4.5以éã§äœæ¥ããŠããå Žåã¯ãæ°ããèªã¿åãå°çšã¯ã©ã¹ã䜿çšããŠã¿ãŠãã ããã
AV1820ã®äœ¿çš
async
é·æçã§äœåŒ·åºŠã®ã¿ã¹ã¯ã«ã®ã¿
䜿çšã
async
ãŸãã䜿çšãããšãã¯ãŒã¯ãããŒå ã®äœãèªåçã«éå§ãããŸãã
Task.Run
ã
Async
ãå¿ èŠãªããžãã¯ãè¿œå ããã ãã§ããããã¯ãçŸåšã®ã¹ã¬ããã®ãªãªãŒã¹ãæå¹ã«ããéåææäœã®å®äºåŸã«åãã¹ã¬ããã«çµæãè¿ãã®ã«åœ¹ç«ã¡ãŸããã€ãŸãã
async
I / Oé¢é£ã®æäœã«ã®ã¿äœ¿çšããŸãã
AV1825䜿çš
Task.Run
é«åŒ·åºŠã®ã¿ã¹ã¯ã®ããã®
è¿œå ã®CPUãªãœãŒã¹ã®å²ãåœãŠã«é¢é£ããæäœãå®è¡ããå¿ èŠãããå Žåã¯ã䜿çšããŠ
Task.Run
ã¹ã¬ããããŒã«ã®æµãã«ä»äºãã¢ããããŒãããŸããçµæãã¡ã€ã³ã¹ã¬ããã«æåã§è¿ãå¿ èŠãããããšã«æ³šæããŠãã ããã
AV1830
await/async
cã®äœ¿çšãé¿ãã
Task.Wait
await
ãšãçŸåšã®ã¹ã¬ããã¯ãããã¯ãããŸããããã³ã³ãã€ã©ã«ã¹ããŒããã·ã³ãæ§ç¯ããå¿ èŠãããããšãéç¥ããã ãã§ãããã ãã
Task.Wait
ãããŒããããã¯ãããããããã¯ãåŒãèµ·ããå¯èœæ§ãããããŸãïŒAV1835ãåç §ïŒã
AV1835
async/await
ã·ã³ã°ã«ã¹ã¬ããç°å¢ã§ã¯çžäºãããã¯ã«æ³šæããŠãã ãã
次ã®éåæã¡ãœãããæ€èšããŠãã ããã
private async Task<string> GetDataAsync() { var result = await MyWebService.GetDataAsync(); return result.ToString(); }
次ã«ã次ã®ããã«ASP.NET MVCã³ã³ãããŒã©ãŒã¡ãœããã§åŒã³åºããŸãã
public ActionResult ActionAsync() { var data = GetDataAsync().Result; return View(data); }
ããã§ããããããã¯ãçºçããŸãã ãªãã§ïŒããããã£ã®getterã¯
Result
æäœ
async
ãå®äºãããŸã§ã¹ã¬ããããããã¯ããŸãããã¡ãœãã
async
ã¯çµæãèªåçã«å ã®ã¹ã¬ããã«è¿ããASP.NETã¯ã·ã³ã°ã«ã¹ã¬ããã®åæã³ã³ããã¹ãã䜿çšããããããäºããåŸ ã¡ç¶ããŸããåæ§ã®åé¡ã¯ãWPFãSilverlightããŸãã¯CïŒ/ XAML Windowsã¹ãã¢ã¢ããªã±ãŒã·ã§ã³ã§ãçºçããå¯èœæ§ããããŸãã詳现ã«ã€ããŠã¯ããã¡ããã芧ãã ããã
ãã¬ãŒã ã¯ãŒã¯ã®äœ¿çšã«é¢ããæšå¥šäºé
AV2201ã®äœ¿çšã¯ãåå空éã®CïŒã®çš®é¡ã®çš®é¡ã®ä»£ããã«ãšã€ãªã¢ã¹
System
ãäŸãã°ã䜿çš
object
ã®ä»£ããã«
Object
ã
string
代ããã«
String
åã³
int
å Žæã«
Int32
ããããã®ãšã€ãªã¢ã¹ã¯ãããªããã£ãåãCïŒèšèªã®ãã¡ãŒã¹ãã¯ã©ã¹ã¡ã³ãã«ããããã«å°å ¥ããããããé©åã«äœ¿çšããŠãã ããã
äŸå€ïŒãã®ãããªã¿ã€ãã®éçèŠçŽ ãåç §ããå Žåãéåžžã¯ã
Int32.Parse()
代ããã«å®å šãªCLSåã䜿çšããã®ãéåžž
int.Parse()
ã§ãã
AV2205ããŒã«ã©ã€ãºããããªãœãŒã¹ãåç §ããããããã£ãå€æ°ããŸãã¯ãã£ãŒã«ãã®ååãæ éã«èšå®ãã
ãã®ã»ã¯ã·ã§ã³ã®æšå¥šäºé ã¯ããšã©ãŒã¡ãã»ãŒãžãã¡ãã¥ãŒããã¹ããªã©ã®ããŒã«ã©ã€ãºããããªãœãŒã¹ã«é©çšãããŸãã
- ãªãœãŒã¹ããŒã«ãã¹ã«ã«è¡šèšã䜿çšãã
- . ,
- -
AV2207ã¢ããªã±ãŒã·ã§ã³ã®å±éäžã«å€æŽããå¿ èŠãããã³ãŒãè¡
ïŒæ¥ç¶æååããµãŒããŒã¢ãã¬ã¹ãªã©ïŒãæ®ããªãã§ãã ããããªãœãŒã¹ãã¡ã€ã«ã
ConnectionStrings
ã¯ã©ã¹ããããã£ã
ConfigurationManager
ãŸãã¯
Settings
Visual Studioã«ãã£ãŠçæãããã¯ã©ã¹ã䜿çšããŸãã
app.config
ãŸãã¯
web.config
ïŒä»ã§ã¯ãªãïŒã䜿çšããŠçŸåšã®èšå®ãç¶æããŸãã
AV2210æé«ã¬ãã«ã®èŠå
ã䜿çšããŠãã«ãããCïŒã³ã³ãã€ã©ã®èŠåã¬ãã«4ã䜿çšããããã«äœæ¥ç°å¢ãæ§æãããèŠåããšã©ãŒãšããŠåŠçããããªãã·ã§ã³ãæå¹ã«ããŸããããã«ãããå¯èœãªéãæé«ã¬ãã«ã®å質ã§ã³ãŒããã³ã³ãã€ã«ã§ããŸãã
AV2215ãã¡ã€ã«ã®å±æ§ãæ éã«èšå ¥ããŠ
AssemblyInfo.cs
ãã ããäŒç€Ÿåã説æãèäœæš©è¡šç€ºãªã©ã®å±æ§ã確èªããŠãã ãããèšå ¥ããŸããããã¹ãŠã®ã¢ã»ã³ããªã«å ±éã®ããŒãžã§ã³çªå·ãšä»ã®ãã£ãŒã«ããåžžã«åãã§ããããšãä¿èšŒãã1ã€ã®æ¹æ³ã¯ã察å¿ããå±æ§ããœãªã¥ãŒã·ã§ã³å ã®ãã¹ãŠã®ãããžã§ã¯ãã§å ±æããã
AssemblyInfo.cs
ãã¡ã€ã«ã«ç§»åãã
SolutionInfo.cs
ããšã§ãã
AV2220åçŽãªåŒã«ã¯LINQã䜿çšããªã
代ããã«ïŒ
var query = from item in items where item.Length > 0;
åå空éã®ã¡ãœããã䜿çšããããšããå§ãããŸã
System.Linq
ïŒ
var query = items.Where(i => i.Length > 0);
ããã«ãLINQã¯ãšãªã¯èªã¿ãããããããã«è€æ°ã®è¡ã«åå²ããå¿ èŠããããŸãããããã£ãŠã2çªç®ã®åŒã¯èªã¿ããããªããŸãã
AV2221å¿åã¡ãœããã®ä»£ããã«ã©ã ãåŒã䜿çšãã
LambdaåŒã¯ãå¿åã¡ãœããã®ããçŸãã代æ¿æ段ãšããŠæ©èœããŸãããããã£ãŠã代ããã«ïŒ
Customer c = Array.Find(customers, delegate(Customer c) { return c.Name == âTomâ; });
ã©ã ãåŒã䜿çšããŸãã
Customer c = Array.Find(customers, c => c.Name == âTomâ);
ãŸãã¯ããã«è¯ãã®ã¯ïŒ
var customer = customers.Where(c => c.Name == âTomâ);
AV2230䜿çšããŒã¯ãŒã
dynamic
ãã®åã®ãªããžã§ã¯ããæäœããã ãã§
ãããŒã¯ãŒã
dynamic
åçèšèªã§äœ¿çšããããã«å°å ¥ãããŸãããã³ã³ãã€ã©ã¯è¿œå ã®ã³ãŒããçæããããšãäœåãªããããããããããã®äœ¿çšã¯æ·±å»ãªããã©ãŒãã³ã¹ã®ããã«ããã¯ãäœæããŸãã
䜿çš
dynamic
ïŒã¯ã©ã¹ã䜿çšããŠåçã«äœæãããã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ã®ã¡ã³ããåç §ããå Žåã«ã®ã¿
Activator
ã代æ¿ãšããŠïŒã
Type.GetProperty()
ããã³
Type.GetMethod()
ãŸãã¯COM Iteropã®çš®é¡ãæ±ããŸãã
AV2235
async/await
代ããã«äœ¿çšããŠã¿ãŠãã ãã
Task
æ°ããCïŒ5.0ããŒã¯ãŒãã䜿çšãããšãã³ãŒãã®èšè¿°ãšèªã¿åãã容æã«ãªããä¿å®ã容æã«ãªããŸããå€æ°ã®éåææäœãäœæããå¿ èŠãããå Žåã§ããããšãã°ããããè¡ã代ããã«ïŒ
public Task<Data> GetDataAsync() { return MyWebService.FetchDataAsync() .ContinueWith(t => new Data (t.Result)); }
次ã®ããã«ã¡ãœããã宣èšããŸãã
public async Task<Data> GetDataAsync() { var result = await MyWebService.FetchDataAsync(); return new Data (result); }
ããã¥ã¡ã³ãã®ã¬ã€ãã©ã€ã³
AV2301ã®æžã蟌ã¿ã³ã¡ã³ããããã¥ã¡ã³ãã®ã¢ã¡ãªã«è±èªã§
AV2305ææžã®ãã¹ãŠ
public
ã
protected
ããã³
internal
ã¿ã€ããšã¡ã³ããŒ
ããªãã®ã³ãŒããææžåã¯ãããªãã®ã¯ã©ã¹ã¯ã©ããå¥ã®å Žæã§äœ¿çšããããšããVisual Studioããã³ãã衚瀺ããããšãã§ããŸããããã«ãã¯ã©ã¹ãé©åã«ããã¥ã¡ã³ãåãããšããããã§ãã·ã§ãã«ã«èŠããã³ãŒãã®ããã¥ã¡ã³ããçæã§ããŸãã
AV2306 XMLããã¥ã¡ã³ããæžããšãã¯å¥ã®éçºè ãèŠããŠãã ããXMLããã¥ã¡ã³ããæžããšãã¯å¥ã®éçºè ãèŠããŠãã ãã
ããã¶ãã圌/圌女ã¯ãœãŒã¹ã³ãŒãã«ã¢ã¯ã»ã¹ã§ããªãã®ã§ãããªãã®ã¿ã€ããã©ã®ããã«äœ¿çšãããããããå®å šã«èª¬æããããšããã¹ãã§ãã
AV2307MSDNããã¥ã¡ã³ã
ã¹ã¿ã€ã«ã䜿çšããïŒMSDN ãªã³ã©ã€ã³ãã«ãã¹ã¿ã€ã«ã«åŸã£ãŠãä»ã®éçºè ãããã¥ã¡ã³ãããã°ããç解ã§ããããã«ããŸãã
ãã³ãïŒGhostDocã¯ããããããŒã䜿çšããŠããã¥ã¡ã³ããäœæããããã®xmlã³ã¡ã³ããçæã§ããŸãã
AV2310ã€ã³ã©ã€ã³ã³ã¡ã³ããé¿ããã³ã¡ã³ã
ã䜿çšããŠã³ãŒãã®ç¹å®ã®ã»ã¯ã·ã§ã³ã説æããå¿ èŠããããšæããå Žåããããããã®ã³ãŒããå¥ã®ã¡ãœããã«å ¥ããŠããã®ç®çãæ確ã«ç€ºãååãä»ããå¿ èŠããããŸãã
AV2316è€éãªãœãªã¥ãŒã·ã§ã³ãšã¢ã«ãŽãªãºã ã説æããããã ãã«ã³ã¡ã³ããæžã
ããªãã®ã³ã¡ã³ããæ¹æ³ã§ã¯ãªããçç±ãšäœã«ã€ããŠã®è³ªåã«çããããã«ããŠãã ãããã³ãŒããããã¯ãèšèã§èª¬æããããšã¯é¿ãã代ããã«ãã³ãŒããèªã人ãããã®ãœãªã¥ãŒã·ã§ã³ãŸãã¯ã¢ã«ãŽãªãºã ãéžæããçç±ãšéæããããšããŠããããšãç解ã§ããããã«ããŠãã ãããå¯èœã§ããã°ã代æ¿ãœãªã¥ãŒã·ã§ã³ãéžæããå Žåã¯ãåçŽãªãœãªã¥ãŒã·ã§ã³ã§åé¡ãçºçããçç±ã説æããŸããAV2318ã³ã¡ã³ãã䜿çšããŠãåŸã§å®è¡ããäœæ¥ã远跡ããªãã§ãã ããã
å®è¡ããå¿ èŠãããäœæ¥ã远跡ããããã«ãã³ãŒããããã¯ã«ToDoãŸãã¯ä»ã®ã³ã¡ã³ããè¿œå ããããšã¯ãè¯ã解決çã®ããã«æãããããããŸãããããããå®éã«ã¯ã誰ããã®ãããªã³ã¡ã³ããå¿ èŠãšããŸãããTeam Foundation Serverãªã©ã®ã¿ã¹ã¯è¿œè·¡ã·ã¹ãã ã䜿çšããŠãæ¬ é¥ã远跡ããŸãã
èšèšã®æšå¥šäºé
AV2400äžè¬çãªã¬ã€ã¢ãŠãã«ãŒã«ã䜿çšãã
- è¡ã®é·ãã130æå以å ã«ä¿ã¡ãŸã
- ã€ã³ãã³ããšããŠ4ã€ã®ã¹ããŒã¹ã䜿çšããã¿ãã䜿çšããªã
- åŒïŒäŸ
if
ïŒïŒãšããŒã¯ãŒãã®éã«ã¹ããŒã¹ã1ã€æ¿å ¥ããŸãã(
ååŸã«ã¹ããŒã¹ã䜿çšããªãã§ãã ãã)
ãäŸïŒ
if (condition == null)
- æŒç®åã®ååŸã«ã¹ããŒã¹ãè¿œå
(
ãªã©+
ã-
ã==
ïŒ -
if
,else
,do
,while
,for
foreach
, - . :
var dto = new ConsumerDto() { Id = 123, Name = âMicrosoftâ, PartnerShip = PartnerShip.Gold, };
- - . , :
methodThatTakesAnAction.Do(x => { // - };
- LINQ- , :
var query = from product in products where product.Price > 10 select product;
ãŸãã¯
var query = from product in products where product.Price > 10 select product;
- LINQ-
from
where
- , . äŸïŒ
if (!string.IsNullOrEmpty(str) && (str != ânewâ))
- è€æ°è¡ã®åŒãã¯ã©ã¹ã¡ã³ããŒãæ¬åŒ§ãéããåŸãç¡é¢ä¿ãªã³ãŒããããã¯ã®åŸãããŒã¯ãŒãã®ååŸã
#region
ããã³using
åå空éãç°ãªãäŒç€Ÿã«å±ããŠããå Žåã¯ãã£ã¬ã¯ãã£ãéã«ç©ºçœè¡ãè¿œå ããŸã
AV2402äŒç€Ÿåã«åŸã£ãŠåå空éãæŽçããã³ã°ã«ãŒãåãã
// Microsoft using System; using System.Collections; using System.XML; // using AvivaSolutions.Business; using AvivaSolutions.Standard; using Telerik.WebControls; using Telerik.Ajax;
AV2406ã¯ã©ã¹ã¡ã³ããŒãå³å¯ã«å®çŸ©ãããé åºã§é 眮ããŸãã
- ãã©ã€ããŒããã£ãŒã«ããšå®æ°ïŒc
#region
ïŒ - ãããªãã¯å®æ°
- èªã¿åãå°çšã®ãããªãã¯éçãã£ãŒã«ã
- å·¥å Žã¡ãœãã
- ã³ã³ã¹ãã©ã¯ã¿ãŒãšãã¡ã€ãã©ã€ã¶ãŒ
- ã€ãã³ã
- ãããªãã¯ããããã£
- ä»ã®ã¡ãœãããšãã©ã€ããŒãããããã£ãåŒã³åºãããé åº
äžè¬çãªé åºãç¶æãããšãä»ã®ããŒã ã¡ã³ããŒãã³ãŒããç°¡åã«ããã²ãŒãã§ããããã«ãªããŸããäžè¬çã«ãæ¬ãèªãã§ãããã®ããã«ããœãŒã¹ãã¡ã€ã«ãäžããäžã«èªãå¿ èŠããããŸããããã«ãããç®çã®ãã©ã°ã¡ã³ããæ€çŽ¢ããéã«ãã¡ã€ã«ãäžäžã«åç §ããå¿ èŠãããå Žåã«ãç¶æ³ãåé¿ã§ããŸãã
AV2407ããŒã¯ãŒãã«ã¯æ³šæãå¿ èŠã§ãã
#region
ããŒã¯ãŒã
#region
ã¯åœ¹ã«ç«ã€ãããããŸããããã¯ã©ã¹ã®äž»ãªç®çãææ§ã«ãããããããŸããããããã£ãŠã以äžã«
#region
ã®ã¿äœ¿çšããŠãã ããã
- ãã©ã€ããŒããã£ãŒã«ããšå®æ°ïŒãã©ã€ããŒãå®çŸ©é åãæãŸããïŒ
- ãã¹ããããã¯ã©ã¹
- ã€ã³ã¿ãŒãã§ã€ã¹å®è£ ïŒã€ã³ã¿ãŒãã§ã€ã¹å®è£ ããã®ã¯ã©ã¹ã®äž»ãªç®çã§ãªãå Žåã®ã¿ïŒ
éèŠãªãªãœãŒã¹
äŒç€Ÿã®ãŠã§ããµã€ã
ãã®ããã¥ã¡ã³ãã¯ãCïŒéçºè ã®æ¥ã ã®ä»äºããããã§ãã·ã§ãã«ã§ããããšãä¿èšŒããåãçµã¿ã®äžéšã§ãããããã£ãŠããããã®æšå¥šäºé ãCodePlex Webãµã€ãã«æçš¿ããŸãããããã¯www.csharpcodingguidelines.comã§ç°¡åã«èŠã€ããããšãã§ããŸãã
ãã®ããã¥ã¡ã³ãã®ææ°ããŒãžã§ã³ã«å ããŠã次ã®å Žæã«ãããŸãã
- ãã®ããã¥ã¢ã«ãžã®çããªã³ã¯ã®ãªã¹ã
- ããŸããŸãªã¿ã€ãã®ã·ã¹ãã çšã®Visual Studio 2010/2012ã®ã«ãŒã«ã»ãã
- 第10ç« ã®æšå¥šäºé ã«åŸãReSharperã®äžé£ã®ã«ãŒã«
- CïŒã§ã³ãŒããæžãããšã®è³ªãè°è«ããããã®ãã©ãããã©ãŒã
䟿å©ãªãªã³ã¯
ãã®ããã¥ã¡ã³ãã§æäŸãããŠããå€ãã®ãªã³ã¯ã«å ããŠããœãããŠã§ã¢ã®å質ã«é¢å¿ããã人ã«ã¯ã次ã®æžç±ãèšäºãããã³ãµã€ãããå§ãããŸãã
å®è·µçãœãããŠã§ã¢æ§ç¯ã®Aãã³ãããã¯ïŒMcConnelã¹ãã£ãŒãïŒïŒã³ãŒããå®äºããŸããããã¯ç§ãä»ãŸã§èªãã äžã§æé«ã®æ¬ã®äžã€ã§ãããœãããŠã§ã¢éçºã®ããããåŽé¢ã«ã€ããŠè©³ãã説æããŠããŸãããã®æ¬ã®ãªãªãžãã«ã¯2004幎ã«æžããããã®ã§ãããæ¬æžã«èšèŒãããŠããããšãã©ãã»ã©é¢é£æ§ãããããèŠããšé©ãã§ããããäžèšã®èšèã®éèŠæ§ãç¥ãããå Žåã¯ã2009幎ã«ãã®æ¬ã®ã¬ãã¥ãŒãæžããŸããã
ã¢ãžã£ã€ã«éçºã®èžè¡ïŒãžã§ãŒã ã¹ã·ã§ã¢ïŒãã¹ã¯ã©ã ããšã¯ã¹ããªãŒã ããã°ã©ãã³ã°ãªã©ã®æ¹æ³è«ãæããå€ãã®ãã©ã¯ãã£ã¹ãç¶²çŸ ããããã1ã€ã®ãã°ãããå æ¬çãªæ ã§ãããããã®æ¹æ³è«ã«ããã«æ £ãããå Žåã¯ããžã§ãŒã ãºã®æ¬ãå¿ ãèªãã§ãã ããã
ãã¡ã€ã³é§åèšèšãšãã¿ãŒã³ã®é©çšïŒCïŒããã³.NETïŒJimmy NilssonïŒã®äŸã䜿çšããŸããäž»é¡æåèšèšïŒDDDïŒãšãã¹ãã«ããéçºïŒTDDïŒã«èå³ãæã¡å§ããæ¬ãããã¯ãç§ã®ééãã®å€ããé¿ããããã«æ°å¹Žåã«èªãã§ããã¹ãæ¬ã®1ã€ã§ãã
ãžã§ã¬ããŒã»Dã»ãã©ãŒã®ããã°ã圌ã¯ãã¯ããã®ããã°ãéå¶ããŠããŸããããéå»æ°å¹Žã«ããã£ãŠããã¹ãããã¿ãŒã³ãããã³èšèšååã«ããéçºã«é¢ããåªããèšäºãå·çããŠããŸããç§ã¯åœŒã®ã¢ã€ãã¢ãšå®ç掻ããã®äŸããå€ããåŠã³ãŸããã
LINQãã¬ãŒã ã¯ãŒã¯ã®èšèšã¬ã€ãã©ã€ã³ãIQueryableã€ã³ã¿ãŒãã§ã€ã¹ã®ç¬èªã®å®è£ ãäœæããéã«åŸãã¹ãäžé£ã®ã«ãŒã«ãšã¬ã€ãã©ã€ã³ã
cïŒasync / awaitã®ãã¹ããã©ã¯ãã£ã¹ããã®ããã¥ã¡ã³ãã§èª¬æãããŠããããã€ãã®æ°ããæšå¥šäºé ã®ãœãŒã¹ãšçè«çæ ¹æ ãèè ã¯ãžã§ã³ã»ã¯ãŒã°ããŒã§ãã