Steven Wilssens http://steven.wilssens.net/ Imagination is more importand then knowledge Steven Wilssens Wed, 15 Mar 2006 10:31:09 GMT newtelligence dasBlog 1.7.5016.2 Steven.Wilssens@telenet.be Steven.Wilssens@telenet.be http://steven.wilssens.net/Trackback.aspx?guid=3c2e75c9-3688-4dd2-ac76-914fda0f100e http://steven.wilssens.net/pingback.aspx http://steven.wilssens.net/PermaLink.aspx?guid=3c2e75c9-3688-4dd2-ac76-914fda0f100e http://steven.wilssens.net/CommentView.aspx?guid=3c2e75c9-3688-4dd2-ac76-914fda0f100e http://steven.wilssens.net/SyndicationService.asmx/GetEntryCommentsRss?guid=3c2e75c9-3688-4dd2-ac76-914fda0f100e 0 These are the presentations and the code demo's Jelle Druyts and I used during the Microsoft Developer & IT Pro Days 2006 in Belgium on 8th of March.
The Best Practices for Application Development (Jelle Druyts and Steven Wilssens):
Best Practices For Application Development.zip
Demo 01 - Enterprise Library.zip
Demo 02 - Enterprise Library and Command Pattern.zip
Demo 03 - Test Driven Development.zip
Best Practices for Advanced Source Control: Beyond CheckOut and CheckIn (Steven Wilssens):
Advanced Source Control - PART I.zip
Advanced Source Control - PART II.zip
Advanced Source Control - PART III.zip
Final version of Slides and Demo's Developer and IT Pro Days 2006 http://steven.wilssens.net/PermaLink.aspx?guid=3c2e75c9-3688-4dd2-ac76-914fda0f100e http://steven.wilssens.net/FinalVersionOfSlidesAndDemosDeveloperAndITProDays2006.aspx Wed, 15 Mar 2006 10:31:09 GMT <font color=#000000>These are the presentations and the code demo's</font> <a href="#topofpage"><font color=#0000ff size=2>Jelle Druyts</font></a> <font color=#000000>and </font><a href="#topofpage"><font color=#0000ff size=2>I</font></a> <font color=#000000>used during the </font><a href="#topofpage"><font color=#0000ff size=2>Microsoft Developer &amp; IT Pro Days 2006 in Belgium on 8th of March.</font></a> <br> <table style="WIDTH: 100%" cellspacing=0 cellpadding=0 border=0> <tbody> <tr> <td style="WIDTH: 30px" valign=top align=left> <span style="FONT-SIZE: 10pt"><font color=#000000>•</font></span></td> <td valign=top align=left> <a href="#topofpage"><font color=#0000ff size=2>The Best Practices for Application Development (Jelle Druyts and Steven Wilssens):</font></a> <br> <a href="/content/binary/Best20Practices20For20Application20Development.zip"><font color=#0000ff size=2>Best Practices For Application Development.zip</font></a> <br> <a href="/content/binary/Demo200120_20Enterprise20Library.zip"><font color=#0000ff size=2>Demo 01 - Enterprise Library.zip</font></a> <br> <a href="/content/binary/Demo200220_20Enterprise20Library20and20Command20Pattern.zip"><font color=#0000ff size=2>Demo 02 - Enterprise Library and Command Pattern.zip</font></a> <br> <a href="/content/binary/Demo200320_20Test20Driven20Development.zip"><font color=#0000ff size=2>Demo 03 - Test Driven Development.zip</font></a> <br> </td> </tr> <tr> <td style="WIDTH: 30px" valign=top align=left> <span style="FONT-SIZE: 10pt"><font color=#000000>•</font></span></td> <td valign=top align=left> <a href="#topofpage"><font color=#0000ff size=2>Best Practices for Advanced Source Control: Beyond CheckOut and CheckIn (Steven Wilssens):</font></a> <br> <a href="/content/binary/Advanced20Source20Control20_20PART20I.zip"><font color=#0000ff size=2>Advanced Source Control - PART I.zip</font></a> <br> <a href="/content/binary/Advanced20Source20Control20_20PART20II.zip"><font color=#0000ff size=2>Advanced Source Control - PART II.zip</font></a> <br> <a href="/content/binary/Advanced20Source20Control20_20PART20III.zip"><font color=#0000ff size=2>Advanced Source Control - PART III.zip</font></a> <br> </td> </tr> </tbody> </table> <img width="0" height="0" src="/aggbug_id_3c2e75c9_3688_4dd2_ac76_914fda0f100e.ashx"> http://steven.wilssens.net/CommentView.aspx?guid=3c2e75c9-3688-4dd2-ac76-914fda0f100e .NET 2.0
http://steven.wilssens.net/Trackback.aspx?guid=ae8f7ce0-a720-4da1-b85a-0f1c2e46e186 http://steven.wilssens.net/pingback.aspx http://steven.wilssens.net/PermaLink.aspx?guid=ae8f7ce0-a720-4da1-b85a-0f1c2e46e186 http://steven.wilssens.net/CommentView.aspx?guid=ae8f7ce0-a720-4da1-b85a-0f1c2e46e186 http://steven.wilssens.net/SyndicationService.asmx/GetEntryCommentsRss?guid=ae8f7ce0-a720-4da1-b85a-0f1c2e46e186 2

During the Developers and IT Pro days 2006, Jelle Druyts and I gave a session on best practices for Application Development.  I have not had the chance to upload the full presentation and the demo's, but would already like to share the second demo with you, which is on the Command Pattern and Enterprise Library.  There are parts of the Command Pattern code that is not fully documented or could be improved (especially the way we handle asynchronous invocation), but we had a deadline that could not be moved!  If you like the Command Pattern implementation and would like to see it improved, do not hesitate to contact me.

 

You can download the finished version of the demo : Finished.zip (1,39 MB)  and the references that are required to run the demo References.zip (729,52 KB)

 

Enjoy!

Demo on Command Pattern and Enterprise Library 2.0 http://steven.wilssens.net/PermaLink.aspx?guid=ae8f7ce0-a720-4da1-b85a-0f1c2e46e186 http://steven.wilssens.net/DemoOnCommandPatternAndEnterpriseLibrary20.aspx Mon, 13 Mar 2006 23:54:59 GMT <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"> <font face=Tahoma color=#000000>During the Developers and IT Pro days 2006, Jelle Druyts and I gave a session on best practices for Application Development.<span style="mso-spacerun: yes">&nbsp; </span>I have not had the chance to upload the full presentation and the demo's, but would already like to share the second demo with you, which is on the Command Pattern and Enterprise Library.&nbsp; There are parts of the Command Pattern code that is not fully documented or could be improved (especially the way we handle asynchronous invocation), but we had a deadline that could not be moved!&nbsp;&nbsp;If you&nbsp;like the Command Pattern implementation and would like to see&nbsp;it improved, do not hesitate to contact me.</font> </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"> <font face=Tahoma color=#000000>&nbsp; </font> </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"> <font face=Tahoma color=#000000>You can download the finished version of the demo : </font><a href="/content/binary/Finished.zip"><font face=Tahoma>Finished.zip (1,39 MB)</font></a><font face=Tahoma>&nbsp;<font color=#000000>and the references that are required to run the demo </font></font><a href="/content/binary/References.zip"><font face=Tahoma>References.zip (729,52 KB)</font></a><font face=Tahoma color=#000000>.&nbsp; </font> </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"> <font face=Tahoma color=#000000></font>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"> <font face=Tahoma color=#000000>Enjoy!</font> </p> <img width="0" height="0" src="/aggbug_id_ae8f7ce0_a720_4da1_b85a_0f1c2e46e186.ashx"> http://steven.wilssens.net/CommentView.aspx?guid=ae8f7ce0-a720-4da1-b85a-0f1c2e46e186 .NET 2.0
http://steven.wilssens.net/Trackback.aspx?guid=a871500d-b41d-40d4-8b7e-08fff94bb179 http://steven.wilssens.net/pingback.aspx http://steven.wilssens.net/PermaLink.aspx?guid=a871500d-b41d-40d4-8b7e-08fff94bb179 http://steven.wilssens.net/CommentView.aspx?guid=a871500d-b41d-40d4-8b7e-08fff94bb179 http://steven.wilssens.net/SyndicationService.asmx/GetEntryCommentsRss?guid=a871500d-b41d-40d4-8b7e-08fff94bb179 2 Generics Part I - Introduction http://steven.wilssens.net/PermaLink.aspx?guid=a871500d-b41d-40d4-8b7e-08fff94bb179 http://steven.wilssens.net/GenericsPartIIntroduction.aspx Wed, 18 May 2005 21:37:04 GMT <p> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"><font color=#000000>Generics or parametric polymorphism allow classes, structs, interfaces, delegates and methods to be parameterized by the type of data they utilize.<span style="mso-spacerun: yes">&nbsp; </span>It has the following advantages over dynamic approaches: </font></span> </p> <p> <table class=MsoTableGrid id=Table8 style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-table-layout-alt: fixed; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellspacing=0 cellpadding=0 border=1> <tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 113.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 29px; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" valign=top width=151> <ul style="MARGIN-TOP: 0in" type=disc> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l6 level1 lfo2; tab-stops: list .5in"> <span style="FONT-FAMILY: Tahoma"><font color=#000000><font size=2>stability </font></font></span> </li> </ul> </td> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; WIDTH: 517px; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 29px; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign=top width=517> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"><font color=#000000><font size=2>stronger compile time type checking </font></font></span> </p> </td> </tr> <tr style="mso-yfti-irow: 1"> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 113.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign=top width=151> <ul style="MARGIN-TOP: 0in" type=disc> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l6 level1 lfo2; tab-stops: list .5in"> <span style="FONT-FAMILY: Tahoma"><font color=#000000><font size=2>expressivity </font></font></span> </li> </ul> </td> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; WIDTH: 517px; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign=top width=517> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"><font color=#000000><font size=2>invariants expressed in type signatures </font></font></span> </p> </td> </tr> <tr style="mso-yfti-irow: 2"> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 113.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign=top width=151> <ul style="MARGIN-TOP: 0in" type=disc> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l6 level1 lfo2; tab-stops: list .5in"> <span style="FONT-FAMILY: Tahoma"><font color=#000000><font size=2>clarity </font></font></span> </li> </ul> </td> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; WIDTH: 517px; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign=top width=517> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"><font color=#000000><font size=2>fewer explicit conversions between data types </font></font></span> </p> </td> </tr> <tr style="mso-yfti-irow: 3; mso-yfti-lastrow: yes"> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 113.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign=top width=151> <ul style="MARGIN-TOP: 0in" type=disc> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l6 level1 lfo2; tab-stops: list .5in"> <span style="FONT-FAMILY: Tahoma"><font color=#000000><font size=2>efficiency </font></font></span> </li> </ul> </td> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; WIDTH: 517px; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign=top width=517> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"><font color=#000000><font size=2>reduce the need for run-time type checks and boxing operations</font></font></span> </p> </td> </tr> </tbody> </table> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> <O:P> <font color=#000000></font> </O:P> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"><strong><font color=#000000>Object-based generic design pattern </font></strong></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <font color=#000000><span style="FONT-FAMILY: Tahoma">Without generics, programmers often use the Object-based generic design pattern.<span style="mso-spacerun: yes">&nbsp; </span>This is a complicated term for something as simple as storing data of any type as an instance of the type </span><span style="FONT-FAMILY: 'Courier New'">Object</span><span style="FONT-FAMILY: Tahoma">.<span style="mso-spacerun: yes">&nbsp; </span>The following </span><span style="FONT-FAMILY: 'Courier New'">List</span><span style="FONT-FAMILY: Tahoma"> class stores its data in an </span><span style="FONT-FAMILY: 'Courier New'">Object</span><span style="FONT-FAMILY: Tahoma"> array and the methods </span><span style="FONT-FAMILY: 'Courier New'">Add</span><span style="FONT-FAMILY: Tahoma"> </span><span style="FONT-FAMILY: Tahoma">and the </span><span style="FONT-FAMILY: 'Courier New'">indexer</span><span style="FONT-FAMILY: Tahoma"> use the </span><span style="FONT-FAMILY: 'Courier New'">Object</span><span style="FONT-FAMILY: Tahoma"> type to accept and return data:</span></font> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"> <table id=Table1 cellspacing=1 cellpadding=1 width="100%" border=1> <tbody> <tr> <td> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">public</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <span style="COLOR: blue">class</span> <font color=#000000>List </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font color=#000000>{ </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="COLOR: blue">private</span> <span style="COLOR: blue">object</span><font color=#000000>[] _items; </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font color=#000000><span style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="COLOR: blue">public</span> <span style="COLOR: blue">object</span> <span style="COLOR: blue">this</span> <font color=#000000>[</font><span style="COLOR: blue">int</span><font color=#000000> index] {...} </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="COLOR: blue">public</span> <span style="COLOR: blue">void</span> <font color=#000000>Add(</font><span style="COLOR: blue">object</span> <span style="COLOR: blue">value</span><font color=#000000>) {...} </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font color=#000000>} </font></span> </p> </td> </tr> </tbody> </table> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <font color=#000000><span style="FONT-FAMILY: Tahoma">The Object-based generic design applied in the above sample provides the </span><span style="FONT-FAMILY: 'Courier New'">List</span><span style="FONT-FAMILY: Tahoma"> class with parameter type flexibility.<span style="mso-spacerun: yes">&nbsp; </span>It is possible to add a value of any type to the </span><span style="FONT-FAMILY: 'Courier New'">List</span><span style="FONT-FAMILY: Tahoma"> but this solution still has following drawbacks: </span></font> </p> <ul style="MARGIN-TOP: 0in" type=disc> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l0 level1 lfo1; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">When the value passed to the </span><span style="FONT-FAMILY: 'Courier New'">Add</span><span style="FONT-FAMILY: Tahoma"> method is a value type, it is automatically boxed.<span style="mso-spacerun: yes">&nbsp; </span></span></font> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l0 level1 lfo1; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">When the value returned by the </span><span style="FONT-FAMILY: 'Courier New'">indexer</span><span style="FONT-FAMILY: Tahoma"> is a value type it must be unboxed with an explicit type cast.<span style="mso-spacerun: yes">&nbsp; </span>Boxing and unboxing operations add a performance overhead because they involve memory allocations and runtime type checks. </span></font> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l0 level1 lfo1; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">When the value returned by the </span><span style="FONT-FAMILY: 'Courier New'">indexer</span><span style="FONT-FAMILY: Tahoma"> is a reference type, an explicit cast to the appropriate type has to be performed.<span style="mso-spacerun: yes">&nbsp; </span>This has a performance penalty for the required runtime checking and is quite tedious to write. </span></font> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l0 level1 lfo1; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">There is no compile time type checking.<span style="mso-spacerun: yes">&nbsp; </span>This may cause that problems do not become apparent until the code is executed and an </span><span style="FONT-FAMILY: 'Courier New'">InvalidCastException</span><span style="FONT-FAMILY: Tahoma"> is thrown. </span></font> </li> </ul> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"><font color=#000000>As you may or may not suspect by now, generics allow us to overcome the abovementioned drawbacks. </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"><font color=#000000></font></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"><strong><font color=#000000>What are Generics? </font></strong></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <font color=#000000><span style="FONT-FAMILY: Tahoma">Generics provide class creators the tools to create types that have type parameters.<span style="mso-spacerun: yes">&nbsp; </span>Rather than forcing conversions to and from </span><span style="FONT-FAMILY: 'Courier New'">Object</span><span style="FONT-FAMILY: Tahoma">, instances of generic types accept the types for which they were created and allow us to store the data without any conversions.<span style="mso-spacerun: yes">&nbsp; </span>The passed type parameter is a placeholder until an actual type is specified during utilization.<span style="mso-spacerun: yes">&nbsp; </span>The following example uses the parameter </span><span style="FONT-FAMILY: 'Courier New'">TypeOfList</span><span style="FONT-FAMILY: Tahoma"> as the type for: </span></font> </p> <ul style="MARGIN-TOP: 0in" type=disc> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l7 level1 lfo7; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">the internal _</span><span style="FONT-FAMILY: 'Courier New'">items</span><span style="FONT-FAMILY: Tahoma"> </span><span style="FONT-FAMILY: Tahoma">array </span></font> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l7 level1 lfo7; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">the parameter type for the </span><span style="FONT-FAMILY: 'Courier New'">Add</span><span style="FONT-FAMILY: Tahoma"> method </span></font> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l7 level1 lfo7; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">the return type for the </span><span style="FONT-FAMILY: 'Courier New'">indexer</span><span style="FONT-FAMILY: Tahoma">.</span></font> </li> </ul> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l7 level1 lfo7; tab-stops: list .5in"> <span style="FONT-FAMILY: Tahoma"> <O:P> <table id=Table2 cellspacing=1 cellpadding=1 width="100%" border=1> <tbody> <tr> <td> <div class=shape style="PADDING-RIGHT: 7.95pt; PADDING-LEFT: 7.95pt; PADDING-BOTTOM: 4.35pt; PADDING-TOP: 4.35pt" v:shape="_x0000_s1026"> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">public</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <span style="COLOR: blue">class</span> <font color=#000000>List &lt;TypeOfList&gt; </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font color=#000000>{ </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="COLOR: blue">private</span> <font color=#000000>TypeOfList[] _items; </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><span style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="COLOR: blue">public</span> <font color=#000000>TypeOfList</font><span style="COLOR: blue"><font color=#000000></font>this</span><font color=#000000> [</font><span style="COLOR: blue">int</span><font color=#000000> index] {...} </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <O:P> <font color=#000000></font> </O:P> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="COLOR: blue">public</span> <span style="COLOR: blue">void</span><font color=#000000> Add(TypeOfList</font><span style="COLOR: blue"> value</span><font color=#000000>){...} </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font color=#000000>}</font></span> </p> </div> </td> </tr> </tbody> </table> </O:P> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <font color=#000000><span style="FONT-FAMILY: Tahoma">When you want use the generic class List, you must specify the actual type for the type substitute </span><span style="FONT-FAMILY: 'Courier New'">TypeOfList</span><span style="FONT-FAMILY: Tahoma">:</span></font> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"> <table id=Table3 cellspacing=1 cellpadding=1 width="100%" border=1> <tbody> <tr> <td> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font color=#000000>List&lt;</font><span style="COLOR: blue">int</span><font color=#000000>&gt; list =</font> <span style="COLOR: blue">new</span><font color=#000000> List&lt;</font><span style="COLOR: blue">int</span><font color=#000000>&gt;();</font></span> </p> </td> </tr> </tbody> </table> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <font color=#000000><span style="FONT-FAMILY: Tahoma">In the constructed type </span><span style="FONT-FAMILY: 'Courier New'">List&lt;int&gt;</span><span style="FONT-FAMILY: Tahoma">, every occurrence of the type substitute </span><span style="FONT-FAMILY: 'Courier New'">TypeOfList</span><span style="FONT-FAMILY: Tahoma"> is replaced with the type argument </span><span style="FONT-FAMILY: 'Courier New'">int</span><span style="FONT-FAMILY: Tahoma">.<span style="mso-spacerun: yes">&nbsp; </span>A constructed type is a generic type that is named with its type parameters.<span style="mso-spacerun: yes">&nbsp; </span>When an instance of the type </span><span style="FONT-FAMILY: 'Courier New'">List&lt;int&gt;</span><span style="FONT-FAMILY: Tahoma"> is used in code, the following applies: </span></font> </p> <ul style="MARGIN-TOP: 0in" type=disc> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l5 level1 lfo3; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">The native storage for the _</span><span style="FONT-FAMILY: 'Courier New'">items</span><span style="FONT-FAMILY: Tahoma"> array is </span><span style="FONT-FAMILY: 'Courier New'">int[]</span><span style="FONT-FAMILY: Tahoma">,</span><span style="FONT-FAMILY: Tahoma"> this provides an improved storage efficiency compared to the non-generic </span><span style="FONT-FAMILY: 'Courier New'">List</span><span style="FONT-FAMILY: Tahoma">.<span style="mso-spacerun: yes">&nbsp; </span></span></font> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l5 level1 lfo3; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">Generics provide strong typing. This means that at compile time and at runtime it will be verified that only </span><span style="FONT-FAMILY: 'Courier New'">int</span><span style="FONT-FAMILY: Tahoma"> </span><span style="FONT-FAMILY: Tahoma">values or values that can be implicitly cast to an </span><span style="FONT-FAMILY: 'Courier New'">int</span><span style="FONT-FAMILY: Tahoma"> </span><span style="FONT-FAMILY: Tahoma">are used as parameter.<span style="mso-spacerun: yes">&nbsp; </span></span></font> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l5 level1 lfo3; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">The </span><span style="FONT-FAMILY: 'Courier New'">indexer</span><span style="FONT-FAMILY: Tahoma"> will return an </span><span style="FONT-FAMILY: 'Courier New'">int</span><span style="FONT-FAMILY: Tahoma"> </span><span style="FONT-FAMILY: Tahoma">value, this eliminates the explicit cast to an </span><span style="FONT-FAMILY: 'Courier New'">int</span><span style="FONT-FAMILY: Tahoma"> when it is retrieved and thus eliminates the unbox operation. </span></font> </li> </ul> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"><font color=#000000>Generic type declarations may have any number of type parameters.<span style="mso-spacerun: yes">&nbsp; </span>The following example illustrates its use:</font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"> <table id=Table4 cellspacing=1 cellpadding=1 width="100%" border=1> <tbody> <tr> <td> <div class=shape style="PADDING-RIGHT: 7.95pt; PADDING-LEFT: 7.95pt; PADDING-BOTTOM: 4.35pt; PADDING-TOP: 4.35pt" v:shape="_x0000_s1028"> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">public</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <span style="COLOR: blue">class</span> <font color=#000000>Dictionary &lt;TypeOfKey, TypeOfValue&gt; </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font color=#000000>{ </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="COLOR: blue">public</span> <span style="COLOR: blue">void</span> <font color=#000000>Add(TypeOfKey key, TypeOfValue</font> <span style="COLOR: blue">value</span><font color=#000000>){...} </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">public</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <font color=#000000>TypeOfValue </font><span style="COLOR: blue">this</span><font color=#000000> [TypeOfKey key] {...} </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font color=#000000>}</font></span> </p> </div> </td> </tr> </tbody> </table> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"><strong><font color=#000000></font></strong></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"><strong><font color=#000000>Constraints </font></strong></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <font color=#000000><span style="FONT-FAMILY: Tahoma">So far the benefits of generics only apply to constructed types.<span style="mso-spacerun: yes">&nbsp; </span>But when you are coding a generic class, you will find that the type of the parameters is still no more specific than the </span><span style="FONT-FAMILY: 'Courier New'">Object</span><span style="FONT-FAMILY: Tahoma"> type.<span style="mso-spacerun: yes">&nbsp; </span>It’s currently impossible to call any type specific method on the parameter values.<span style="mso-spacerun: yes">&nbsp; </span>To provide us with this information C# permits an optional list of constraints to be supplied for each type parameter.<span style="mso-spacerun: yes">&nbsp; </span>A type parameter constraint allows you to specify a requirement that a type must fulfill.<span style="mso-spacerun: yes">&nbsp; </span>Constraints are declared using the word </span><span style="FONT-FAMILY: 'Courier New'">where</span><span style="FONT-FAMILY: Tahoma">, followed by: </span></font> </p> <ul style="MARGIN-TOP: 0in" type=disc> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l1 level1 lfo4; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">The name of the parameter; </span></font> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l1 level1 lfo4; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">a class type (optionally); </span></font> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l1 level1 lfo4; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">interface types (optionally); </span></font> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l1 level1 lfo4; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">the </span><span style="FONT-FAMILY: 'Courier New'">new()</span><span style="FONT-FAMILY: Tahoma"> </span><span style="FONT-FAMILY: Tahoma">constraint, that allows you to specify the requirement for a public parameterless constructor (optionally).</span> </font> </li> </ul> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"></span> <table id=Table5 cellspacing=1 cellpadding=1 width="100%" border=1> <tbody> <tr> <td> <div class=shape style="PADDING-RIGHT: 7.95pt; PADDING-LEFT: 7.95pt; PADDING-BOTTOM: 4.35pt; PADDING-TOP: 4.35pt" v:shape="_x0000_s1030"> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">public</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <span style="COLOR: blue">class</span><font color=#000000> Dictionary &lt;TypeOfKey, TypeOfValue&gt; </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font color=#000000>where TypeOfKey: IComparable&lt;TypeOfKey&gt; </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font color=#000000><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>where TypeOfValue: IPersistable,</font> <span style="COLOR: blue">new</span><font color=#000000> () </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font color=#000000>{ </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">public</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <span style="COLOR: blue">void</span> <font color=#000000>Add(TypeOfKey key, TypeOfValue</font> <span style="COLOR: blue">value</span><font color=#000000>) {…} </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font color=#000000>}<span style="COLOR: blue"> </span></font></span> </p> </div> </td> </tr> </tbody> </table> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <font color=#000000><span style="FONT-FAMILY: Tahoma">Given the abovementioned declaration, where the type argument for </span><span style="FONT-FAMILY: 'Courier New'">TypeOfKey </span><span style="FONT-FAMILY: Tahoma">is constrained to implement </span><span style="FONT-FAMILY: 'Courier New'">IComparable</span><span style="FONT-FAMILY: Tahoma"> the following applies: </span></font> </p> <ul style="MARGIN-TOP: 0in" type=disc> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l2 level1 lfo8; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">the compiler guarantees that any type argument supplied for </span><span style="FONT-FAMILY: 'Courier New'">TypeOfKey </span><span style="FONT-FAMILY: Tahoma">implements </span><span style="FONT-FAMILY: 'Courier New'">IComparable;</span><span style="FONT-FAMILY: Tahoma"> </span></font> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l2 level1 lfo8; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">All members of </span><span style="FONT-FAMILY: 'Courier New'">IComparable</span><span style="FONT-FAMILY: Tahoma"> are directly available on values of the type parameter </span><span style="FONT-FAMILY: 'Courier New'">TypeOfKey.</span></font> </li> </ul> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l2 level1 lfo8; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: 'Courier New'"></span></font><font color=#000000><span style="FONT-FAMILY: 'Courier New'"> <table id=Table6 cellspacing=1 cellpadding=1 width="100%" border=1> <tbody> <tr> <td> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">public</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <span style="COLOR: blue">void </span><font color=#000000>Add (TypeOfKey key, TypeOfValue value)</font></span> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">{</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font color=#000000> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">if</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> (<font color=#000000>key.CompareTo(</font><span style="COLOR: blue">value</span><font color=#000000>) &lt; 0 {…} </font></span> </p> } <div> </div> </td> </tr> </tbody> </table> </span></font> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l2 level1 lfo8; tab-stops: list .5in"> <span style="FONT-FAMILY: Tahoma"><font color=#000000><strong></strong></font></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l2 level1 lfo8; tab-stops: list .5in"> <span style="FONT-FAMILY: Tahoma"><font color=#000000><strong>Generic Methods</strong> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <font color=#000000><span style="FONT-FAMILY: Tahoma">When you only need a type parameter in a particular method, you will probably want to use a generic method.<span style="mso-spacerun: yes">&nbsp; </span>A generic method has one or more type parameters specified between </span><span style="FONT-FAMILY: 'Courier New'">&lt;</span><span style="FONT-FAMILY: Tahoma"> and </span><span style="FONT-FAMILY: 'Courier New'">&gt;</span><span style="FONT-FAMILY: Tahoma"> delimiters after the method name.<span style="mso-spacerun: yes">&nbsp; </span>The type parameters can be used within the: </span></font> </p> <ul style="MARGIN-TOP: 0in" type=disc> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l3 level1 lfo5; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">parameter list </span></font> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l3 level1 lfo5; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">return type </span></font> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l3 level1 lfo5; tab-stops: list .5in"> <span style="FONT-FAMILY: Tahoma"><font color=#000000>body of the method.<span style="mso-spacerun: yes">&nbsp; </span></font></span> </li> </ul> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <font color=#000000><span style="FONT-FAMILY: Tahoma">A generic </span><span style="FONT-FAMILY: 'Courier New'">AddDictionary</span><span style="FONT-FAMILY: Tahoma"> </span><span style="FONT-FAMILY: Tahoma">will probably look like this:</span></font> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"> <table id=Table7 cellspacing=1 cellpadding=1 width="100%" border=1> <tbody> <tr> <td> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">public</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <span style="COLOR: blue">void</span><font color=#000000> AddDictionary (Dictionary&lt;TypeOfKey, TypeOfValue&gt; dictionary) {…} </font></span> </p> </td> </tr> </tbody> </table> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"></span><span style="FONT-FAMILY: Tahoma"></span><span style="FONT-FAMILY: Tahoma"></span><span style="FONT-FAMILY: Tahoma"> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"><strong><font color=#000000></font></strong></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"><strong><font color=#000000>Good news? </font></strong></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"> <span style="FONT-FAMILY: Tahoma"><font color=#000000>Yes, there are least 4 more posts to come on generics:<span style="mso-spacerun: yes">&nbsp; </span></font></span> </p> <ul style="MARGIN-TOP: 0in" type=disc> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l0 level1 lfo1; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">Generics Part II – Generic Declarations </span></font> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l0 level1 lfo1; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">Generics Part III - Advanced Generics; </span></font> <li class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l0 level1 lfo1; tab-stops: list .5in"> <font color=#000000><span style="FONT-FAMILY: Tahoma">Generics Part IV - Generic Performance and Guidelines; </span></font> <li style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-list: l0 level1 lfo1; tab-stops: list .5in"> <span style="FONT-FAMILY: Tahoma"><font color=#000000>Generics Part V - Generic Implementation or what I make of it. </font></span> </li> </ul> </span>>><img width="0" height="0" src="/aggbug_id_a871500d_b41d_40d4_8b7e_08fff94bb179.ashx"> http://steven.wilssens.net/CommentView.aspx?guid=a871500d-b41d-40d4-8b7e-08fff94bb179 .NET 2.0