<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>New Things I Learned</title>
        <link>http://geekswithblogs.net/NewThingsILearned/Default.aspx</link>
        <description> </description>
        <language>en-US</language>
        <copyright>Muljadi Budiman</copyright>
        <managingEditor>muljadibudiman@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <image>
            <title>New Things I Learned</title>
            <url>http://geekswithblogs.net/images/RSS2Image.gif</url>
            <link>http://geekswithblogs.net/NewThingsILearned/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>Get return value from stored procedure</title>
            <category>.NET</category>
            <category>SQL</category>
            <link>http://geekswithblogs.net/NewThingsILearned/archive/2008/09/17/get-return-value-from-stored-procedure.aspx</link>
            <description>&lt;p&gt;&lt;span class="Apple-style-span" style="WORD-SPACING: 0px; FONT: 12px Arial; TEXT-TRANSFORM: none; COLOR: rgb(64,64,64); TEXT-INDENT: 0px; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0"&gt;Recently we changed our DAC layer from using inline SQL to stored procedures in the database. On some of these SQL, we did record deletion (usually only 1 record), and we just execute it via &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.idbcommand.executenonquery.aspx"&gt;IDBCommand.ExecuteNonQuery()&lt;/a&gt; and then check the return value to see how many records were affected (which should be 1) for verification that the query actually does something. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="Apple-style-span" style="WORD-SPACING: 0px; FONT: 12px Arial; TEXT-TRANSFORM: none; COLOR: rgb(64,64,64); TEXT-INDENT: 0px; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0"&gt;With the change to stored procedure, we just return 1 in the stored procedure if the delete is successful. However, the calling code then started to show these deletions as errors. Apparently ExecuteNonQuery only returns the number of affected rows on SELECT, INSERT and DELETE statements; for everything else it returns -1.  So I tried to figure out how to get a return value from a stored procedure.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="Apple-style-span" style="WORD-SPACING: 0px; FONT: 12px Arial; TEXT-TRANSFORM: none; COLOR: rgb(64,64,64); TEXT-INDENT: 0px; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0"&gt;Let's assume a simplistic stored procedure as follows:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="Apple-style-span" style="WORD-SPACING: 0px; FONT: 12px Arial; TEXT-TRANSFORM: none; COLOR: rgb(64,64,64); TEXT-INDENT: 0px; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0"&gt;
&lt;table cellspacing="1" cellpadding="1" width="200" summary="" border="1"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;ALTER&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt"&gt; &lt;span style="COLOR: blue"&gt;PROC&lt;/span&gt; ReturnOnly&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;AS&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;BEGIN&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;      &lt;span style="COLOR: blue"&gt;RETURN&lt;/span&gt; 5&lt;/span&gt;&lt;/div&gt;
            &lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;END&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;span class="Apple-style-span" style="WORD-SPACING: 0px; FONT: 12px Arial; TEXT-TRANSFORM: none; COLOR: rgb(64,64,64); TEXT-INDENT: 0px; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0"&gt;
&lt;p&gt;You can't use ExecuteScalar to get the returned value, and ExecuteNonQuery will always return -1.  To get the value back, you need to add a return value parameter to the command.  The name of the parameter is not important.  The code to get the value returned by that procedure will be as follows:
&lt;/p&gt;&lt;table style="WIDTH: 622px; HEIGHT: 23px" cellspacing="1" cellpadding="1" width="622" summary="" border="1"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;private&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt"&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; ExecuteStoredProcedure(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; storedProcedureName)&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;{&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;   &lt;span style="COLOR: #2b91af"&gt;SqlConnection&lt;/span&gt; connection = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SqlConnection&lt;/span&gt;(connectionString);&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt; &lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;   &lt;span style="COLOR: green"&gt;// Command - specify as StoredProcedure&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;   &lt;span style="COLOR: #2b91af"&gt;SqlCommand&lt;/span&gt; command = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SqlCommand&lt;/span&gt;(storedProcedureName, connection);&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;   command.CommandType = &lt;span style="COLOR: #2b91af"&gt;CommandType&lt;/span&gt;.StoredProcedure;&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt; &lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;   &lt;span style="COLOR: green"&gt;// Return value as parameter&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;   &lt;span style="COLOR: #2b91af"&gt;SqlParameter&lt;/span&gt; returnValue = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SqlParameter&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"returnVal"&lt;/span&gt;, &lt;span style="COLOR: #2b91af"&gt;SqlDbType&lt;/span&gt;.Int);&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;   returnValue.Direction = &lt;span style="COLOR: #2b91af"&gt;ParameterDirection&lt;/span&gt;.ReturnValue;&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;   command.Parameters.Add(returnValue);&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt; &lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="COLOR: green"&gt;    // Execute the stored procedure&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;   connection.Open();&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;   command.ExecuteNonQuery();&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;   connection.Close();&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt; &lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;   &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Convert&lt;/span&gt;.ToInt32(returnValue.Value);&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 10pt"&gt;&lt;span style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%"&gt;}&lt;/span&gt;&lt;/div&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt; &lt;/p&gt;
&lt;/span&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=125243"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=125243" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/NewThingsILearned/aggbug/125243.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Muljadi Budiman</dc:creator>
            <guid>http://geekswithblogs.net/NewThingsILearned/archive/2008/09/17/get-return-value-from-stored-procedure.aspx</guid>
            <pubDate>Wed, 17 Sep 2008 16:57:15 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/NewThingsILearned/comments/125243.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/NewThingsILearned/archive/2008/09/17/get-return-value-from-stored-procedure.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/NewThingsILearned/comments/commentRss/125243.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/NewThingsILearned/services/trackbacks/125243.aspx</trackback:ping>
        </item>
        <item>
            <title>Returning Cursor from Stored Procedure Executing Dynamic Query</title>
            <category>SQL</category>
            <link>http://geekswithblogs.net/NewThingsILearned/archive/2008/08/26/returning-cursor-from-stored-procedure-executing-dynamic-query.aspx</link>
            <description>I usually stay on the C# development of things, and rarely venture to create SQL statements/code, other than the occasional SELECT / UPDATE / INSERT.  However, we have a requirement from our Product Management group to DELETE records permanently from the database.  We have proper enforced foreign keys in our DB schema, so one option we have is to create a stored procedure to help deletion, which will walk thru the referencing foreign keys to the record being deleted and then also delete those records (the children records essentially).  Yes, I know records should not be deleted (it should just be marked as deleted or inactive or something), but it was a requirements insistence where my opinion was overridden.&lt;br /&gt;
&lt;br /&gt;
Having the stored procedure (hence I'll refer to this as sproc) is nice since consumer just need to call the same sproc passing in the table name &amp;amp; record id to delete, and the sproc will do the heavy lifting.  However, the sproc has some tasks to solve; since children records can contain further children records, the sproc needs to call itself recursively.  Since the sproc needs to query different tables (depending on which record is deleted), the sproc has to build dynamic SQL statements and execute that.  Since you need the values of the record Ids that references the parent (so it can see if those records have further children), you also need a CURSOR to loop thru those Ids).&lt;br /&gt;
&lt;br /&gt;
Separately, each of the problem is fairly simple enough, sprocs can call itself recursively, you can create sprocs that execute dynamic SQL, and you can have sprocs that has a CURSOR as OUTPUT.  However when you combine them together, I consider them to be a fairly neat challenge to try to tackle.  The hard part is actually with getting a CURSOR back from a dynamic SQL, so I'm going to focus on that part.&lt;br /&gt;
&lt;br /&gt;
To execute dynamic SQL, you need to use the built-in sp_executesql sproc in SQL Server.  The sp_executesql sproc can accept the following parameters:&lt;br /&gt;
&lt;ol&gt;
    &lt;li&gt;The SQL statement that will be executed&lt;/li&gt;
    &lt;li&gt;The parameters &amp;amp; types that's needed by the SQL statement (#1) in text format&lt;/li&gt;
    &lt;li&gt;The actual parameters to use in that SQL statement&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
So, essentially sp_executesql will create a stored procedure, containing the SQL statement passed (#1), with the parameter list of that sproc as defined in #2 and then it will invoke that newly created stored procedure, passing in the parameters as defined in the latter parameters.&lt;br /&gt;
&lt;br /&gt;
To solve the problem, then we just need to create a dynamic SQL that has a CURSOR parameter which is an OUTPUT parameter.  The following test sproc demonstrates this:&lt;br /&gt;
&lt;br /&gt;
&lt;table cellspacing="1" cellpadding="1" border="1" align="" summary="" style="width: 692px; height: 828px;"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;"&gt;ALTER&lt;/span&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt; &lt;span style="color: blue;"&gt;PROC&lt;/span&gt; TestProc&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;"&gt;AS&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: blue;"&gt;DECLARE&lt;/span&gt; @dynamicSQL &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: gray;"&gt;(&lt;/span&gt;200&lt;span style="color: gray;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: green;"&gt;-- Have code that will construct the dynamic SQL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: blue;"&gt;SET&lt;/span&gt; @dynamicSQL &lt;span style="color: gray;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'SELECT FirstName FROM Contacts'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;; color: red;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: green;"&gt;-- The cursor that will be filled by the dynamic SQL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: blue;"&gt;DECLARE&lt;/span&gt; @outputCursor &lt;span style="color: blue;"&gt;CURSOR&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: green;"&gt;-- Create the dynamic SQL to fill a CURSOR instead&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: blue;"&gt;SET&lt;/span&gt; @dynamicSQL &lt;span style="color: gray;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'SET @outputCursor = CURSOR FORWARD_ONLY STATIC FOR '&lt;/span&gt; &lt;span style="color: gray;"&gt;+&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;              &lt;/span&gt;@dynamicSQL &lt;span style="color: gray;"&gt;+&lt;/span&gt; &lt;span style="color: red;"&gt;' ; OPEN @outputCursor'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;; color: red;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: green;"&gt;-- Execute dynamic sql&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: blue;"&gt;exec&lt;/span&gt; &lt;span style="color: maroon;"&gt;sp_executesql&lt;/span&gt;&lt;span style=""&gt;                &lt;/span&gt;&lt;span style=""&gt;  &lt;/span&gt;&lt;span style="color: green;"&gt;-- sp_executesql will essentially create a sproc&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;              &lt;/span&gt;@dynamicSQL&lt;span style="color: gray;"&gt;,&lt;/span&gt;&lt;span style=""&gt;               &lt;/span&gt;&lt;span style=""&gt;  &lt;/span&gt;&lt;span style="color: green;"&gt;-- The SQL statement to execute (body of sproc)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;              &lt;/span&gt;N&lt;span style="color: red;"&gt;'@outputCursor CURSOR OUTPUT'&lt;/span&gt;&lt;span style="color: gray;"&gt;,&lt;/span&gt; &lt;span style="color: green;"&gt;-- The parameter list for the sproc: OUTPUT CURSOR&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;              &lt;/span&gt;@outputCursor &lt;span style="color: blue;"&gt;OUTPUT&lt;/span&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style=""&gt;  &lt;/span&gt;&lt;span style="color: green;"&gt;-- The parameter to pass to the sproc: the CURSOR&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;; color: green;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: green;"&gt;-- Code that will just output the values from the cursor&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: blue;"&gt;DECLARE&lt;/span&gt; @firstName &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: gray;"&gt;(&lt;/span&gt;200&lt;span style="color: gray;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: blue;"&gt;FETCH&lt;/span&gt; &lt;span style="color: blue;"&gt;NEXT&lt;/span&gt; &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; @outputCursor &lt;span style="color: blue;"&gt;INTO&lt;/span&gt; @firstName&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: green;"&gt;-- Loop while there're more things in the cursor&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: blue;"&gt;WHILE&lt;/span&gt; &lt;span style="color: fuchsia;"&gt;@@FETCH_STATUS&lt;/span&gt; &lt;span style="color: gray;"&gt;=&lt;/span&gt; 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: blue;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;              &lt;/span&gt;&lt;span style="color: blue;"&gt;PRINT&lt;/span&gt; @firstName&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;              &lt;/span&gt;&lt;span style="color: blue;"&gt;FETCH&lt;/span&gt; &lt;span style="color: blue;"&gt;NEXT&lt;/span&gt; &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; @outputCursor &lt;span style="color: blue;"&gt;INTO&lt;/span&gt; @firstName&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: blue;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: green;"&gt;-- Be nice, close &amp;amp; deallocate cursor&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;" class="MsoNormal"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: blue;"&gt;CLOSE&lt;/span&gt; @outputCursor&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style="color: blue;"&gt;DEALLOCATE&lt;/span&gt; @outputCurso&lt;/span&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;r&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
I just choose to use a simple SELECT to a table as the dynamic SQL statement; you can make it to be whatever SELECT is needed based on parameter being passed.  Then the sproc declares a CURSOR, which will then be used to contain the result of the SQL statement.  The whole text, including the CURSOR is the dynamic SQL we want to execute.  sp_executesql is then called with the SQL statement, we then define the statement to have 1 parameter (which is the CURSOR as an OUTPUT parameter), and then we pass in the cursor as the object to pass into the dynamic SQL to be executed.  The latter half of the code just loops thru the cursor to proof that the results are proper.&lt;br /&gt;
&lt;br /&gt;
Not having dealt with much SQL code, this was an interesting journey for me.  There are other ways to solve the problem (DELETE records), we can use cascade delete, but it doesn't support self-referencing tables.  In the end we didn't use this approach, instead we just create a sproc for each table that needs to be deleted; it seems like a heck of a lot of maintenance job, but I'll let the DBA handle that.&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=124699"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=124699" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/NewThingsILearned/aggbug/124699.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Muljadi Budiman</dc:creator>
            <guid>http://geekswithblogs.net/NewThingsILearned/archive/2008/08/26/returning-cursor-from-stored-procedure-executing-dynamic-query.aspx</guid>
            <pubDate>Tue, 26 Aug 2008 16:49:18 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/NewThingsILearned/comments/124699.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/NewThingsILearned/archive/2008/08/26/returning-cursor-from-stored-procedure-executing-dynamic-query.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/NewThingsILearned/comments/commentRss/124699.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/NewThingsILearned/services/trackbacks/124699.aspx</trackback:ping>
        </item>
        <item>
            <title>Refresh / Update WPF controls</title>
            <category>WPF</category>
            <category>.NET</category>
            <link>http://geekswithblogs.net/NewThingsILearned/archive/2008/08/25/refresh--update-wpf-controls.aspx</link>
            <description>Sometime in the past, a friend asked me how to update a control to show status while his code is doing a loop of stuff.  Essentially changing the text of a label (or sophisticatedly we can say a text-based progress bar).  In my past coding with MFC and WinForms, it's fairly easy enough, you just invalidate and do an update (Invalidate / UpdateWindow in MFC or Invalidate / Update in WinForms).  This approach also coincides with how Windows UI operate, where you specify the region that needs to be redrawn and then you send a message to the message pump for that control to paint itself.&lt;br /&gt;
&lt;br /&gt;
So, I expected something similar (if not exactly the same) to also be present in WPF; much to my surprise, there is no equivalent.   All my internet searches actually shows how to do this using background thread - it is the approach that needs to be taken in a proper programming context, however there are times when you just want to do something quick &amp;amp; dirty or you want to augment an existing app / port where you don't want to introduce new elements.  There are also considerations to be made when both UI and worker thread access the same data, especially with regard to data binding (see &lt;a href="http://geekswithblogs.net/NewThingsILearned/archive/2008/01/16/have-worker-thread-update-observablecollection-that-is-bound-to-a.aspx"&gt;my post &lt;/a&gt;about collection change not supporting multi-threading out of the box).&lt;br /&gt;
&lt;br /&gt;
So, I've decided to add a helper method to refresh a WPF control.  I really appreciated the Refresh method in WinForms (which executes both Invalidate &amp;amp; Update), so I'm renaming my method to be Refresh as well.  The code snippet below also show some C# specific techniques, namely: anonymous delegates and extension methods.&lt;br /&gt;
&lt;br /&gt;
&lt;table width="600" cellspacing="1" cellpadding="1" border="1" align="" summary=""&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;"&gt;public&lt;/span&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;ExtensionMethods&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;{&lt;/span&gt;&lt;/div&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;   &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Action&lt;/span&gt; EmptyDelegate = &lt;span style="color: blue;"&gt;delegate&lt;/span&gt;() { };&lt;/span&gt;&lt;/p&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt; &lt;/div&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;   &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Refresh(&lt;span style="color: blue;"&gt;this&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;UIElement&lt;/span&gt; uiElement)&lt;/span&gt;&lt;/p&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;   {&lt;/span&gt;&lt;/div&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;      uiElement.Dispatcher.Invoke(&lt;span style="color: rgb(43, 145, 175);"&gt;DispatcherPriority&lt;/span&gt;.Render, EmptyDelegate);&lt;/span&gt;&lt;/div&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;   }&lt;/span&gt;&lt;/div&gt;
            &lt;div&gt;&lt;span style="font-size: 8pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;"&gt;}&lt;/span&gt;&lt;/div&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;"&gt;private&lt;/span&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; LoopingMethod()&lt;/span&gt;&lt;/p&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;{&lt;/span&gt;&lt;/div&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;   &lt;span style="color: blue;"&gt;for&lt;/span&gt; (&lt;span style="color: blue;"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 10; i++)&lt;/span&gt;&lt;/div&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;   {&lt;/span&gt;&lt;/div&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;      label1.Content = i.ToString();&lt;/span&gt;&lt;/div&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;      label1.Refresh();&lt;/span&gt;&lt;/div&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;      &lt;span style="color: rgb(43, 145, 175);"&gt;Thread&lt;/span&gt;.Sleep(500);&lt;/span&gt;&lt;/div&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;   }&lt;/span&gt;&lt;/div&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;}&lt;/span&gt;&lt;/div&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
The LoopingMethod is just the method I use in my Window class to update the label (updating the progress) and then the code does some heavy lifting (Sleep &lt;img src="/Providers/BlogEntryEditor/FCKeditor/editor/images/smiley/msn/regular_smile.gif" alt="" /&gt;).  The Refresh method is the extension method that takes any UI element and then calls that UIElement's Dispatcher's Invoke method.  The trick is to call the Invoke method with DispatcherPriority of Render or lower.  Since we don't want to do anything, I created an empty delegate.  So how come this achieves refresh functionality?&lt;br /&gt;
&lt;br /&gt;
When the DispatcherPriority is set to Render (or lower), the code will then execute all operations that are of that priority or higher.  In the example, the code already sets label1.Content to something else, which will result in a render operation.  So by calling Dispatcher.Invoke, the code essentially asks the system to execute all operations that are Render or higher priority, thus the control will then render itself (drawing the new content).  Afterwards, it will then execute the provided delegate (which is our empty method).&lt;br /&gt;
&lt;br /&gt;
Pretty weird; there was a post somewhere in my google search that led me this route, and I was surprised as to how it worked.  I couldn't find it anymore, but credit where credit is due, someone else figured out that Invoke-ing a Render or lower priority task will result in the UI being redrawn.&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=124665"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=124665" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/NewThingsILearned/aggbug/124665.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Muljadi Budiman</dc:creator>
            <guid>http://geekswithblogs.net/NewThingsILearned/archive/2008/08/25/refresh--update-wpf-controls.aspx</guid>
            <pubDate>Mon, 25 Aug 2008 15:22:11 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/NewThingsILearned/comments/124665.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/NewThingsILearned/archive/2008/08/25/refresh--update-wpf-controls.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/NewThingsILearned/comments/commentRss/124665.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/NewThingsILearned/services/trackbacks/124665.aspx</trackback:ping>
        </item>
        <item>
            <title>Calling Generic Method when given a type</title>
            <category>.NET</category>
            <link>http://geekswithblogs.net/NewThingsILearned/archive/2008/08/22/calling-generic-method-when-given-a-type.aspx</link>
            <description>Every now and then I have a need to call a generic method, but I can't quite call it generically.  Usually that particular situation involves needing to call a generic method, and I have the type for that generic method.  There are various reasons/examples of why anyone would get to this point, in my case we have an infrastructure code that can deal with objects generically, but  because it is infrastructure code, we can't have it refer to the actual entity classes that are in the higher layer/tier.&lt;br /&gt;
&lt;br /&gt;
However, if we only have the type, we can't just call the method as is, we have to call it via reflection.  And as much as I like reflection, it has some drawbacks.  Consider the following snippet:&lt;br /&gt;
&lt;table width="600" cellspacing="1" cellpadding="1" border="1" align="" summary=""&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;"&gt;public&lt;/span&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; InvokeGenericMethod(&lt;span style="color: blue;"&gt;object&lt;/span&gt; o)&lt;/span&gt;&lt;/p&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;{&lt;/span&gt;&lt;/div&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;   &lt;span style="color: rgb(43, 145, 175);"&gt;MethodInfo&lt;/span&gt; mi = &lt;span style="color: blue;"&gt;this&lt;/span&gt;.GetType().GetMethod(&lt;span style="color: rgb(163, 21, 21);"&gt;"MyGenericTestMethod"&lt;/span&gt;, &lt;span style="color: rgb(43, 145, 175);"&gt;BindingFlags&lt;/span&gt;.DeclaredOnly | &lt;span style="color: rgb(43, 145, 175);"&gt;BindingFlags&lt;/span&gt;.NonPublic | &lt;span style="color: rgb(43, 145, 175);"&gt;BindingFlags&lt;/span&gt;.Instance);&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;   mi = mi.MakeGenericMethod(&lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Type&lt;/span&gt;[] { o.GetType() });&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;   mi.Invoke(&lt;span style="color: blue;"&gt;this&lt;/span&gt;, &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: blue;"&gt;object&lt;/span&gt;[] { o });&lt;/span&gt;&lt;/p&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;}&lt;/span&gt;&lt;/div&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt; &lt;/div&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;"&gt;private&lt;/span&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt; &lt;span style="color: blue;"&gt;string&lt;/span&gt; MyGenericTestMethod&amp;lt;T&amp;gt;(T value)&lt;/span&gt;&lt;/p&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;{&lt;/span&gt;&lt;/div&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;   &lt;span style="color: blue;"&gt;return&lt;/span&gt; value.GetType().ToString();&lt;/span&gt;&lt;/p&gt;
            &lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;}&lt;/span&gt;&lt;br /&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
To call the method (it is private), I have to call Type.GetMethod with some not very nice looking parameters.  The name supplied is in quotes; as such if the actual method name is changed, this code will still compile, it'll just crash when actually ran.  Mind you, the code works; it's just not very maintenance-friendly.&lt;br /&gt;
&lt;br /&gt;
A trick I use for this then is to use delegates as follows:
&lt;table width="600" cellspacing="1" cellpadding="1" border="1" align="" summary=""&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;"&gt;public&lt;/span&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; InvokeGenericMethod(&lt;span style="color: blue;"&gt;object&lt;/span&gt; o)&lt;/span&gt;&lt;/p&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;{&lt;/span&gt;&lt;/div&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;   &lt;span style="color: rgb(43, 145, 175);"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color: blue;"&gt;string&lt;/span&gt;, &lt;span style="color: blue;"&gt;string&lt;/span&gt;&amp;gt; temp = MyGenericTestMethod&amp;lt;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&amp;gt;;&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;   &lt;span style="color: rgb(43, 145, 175);"&gt;MethodInfo&lt;/span&gt; mi = temp.Method.GetGenericMethodDefinition();&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;   mi = mi.MakeGenericMethod(&lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Type&lt;/span&gt;[] { o.GetType() });&lt;/span&gt;&lt;/p&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;   mi.Invoke(&lt;span style="color: blue;"&gt;this&lt;/span&gt;, &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: blue;"&gt;object&lt;/span&gt;[] { o });&lt;/span&gt;&lt;/p&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;}&lt;/span&gt;&lt;/div&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt; &lt;/div&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;"&gt;private&lt;/span&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt; &lt;span style="color: blue;"&gt;string&lt;/span&gt; MyGenericTestMethod&amp;lt;T&amp;gt;(T value)&lt;/span&gt;&lt;/p&gt;
            &lt;div style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;{&lt;/span&gt;&lt;/div&gt;
            &lt;p style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="font-size: 8pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;   &lt;span style="color: blue;"&gt;return&lt;/span&gt; value.GetType().ToString();&lt;/span&gt;&lt;/p&gt;
            &lt;div&gt;&lt;span style="font-size: 8pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;"&gt;}&lt;/span&gt;&lt;/div&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
By using delegates, I no longer need to use reflections to get the method to call; I just point to the method as a delegate, and then create a generic method definition from that delegate.  Everything after that is still the same.  One nice benefit to this is if the method name is changed, the refactoring engine will also change the delegate reference, and if it doesn't the code will fail at compile-time.  Nicer, cleaner looking code as well, IMHO.&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=124628"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=124628" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/NewThingsILearned/aggbug/124628.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Muljadi Budiman</dc:creator>
            <guid>http://geekswithblogs.net/NewThingsILearned/archive/2008/08/22/calling-generic-method-when-given-a-type.aspx</guid>
            <pubDate>Fri, 22 Aug 2008 14:41:54 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/NewThingsILearned/comments/124628.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/NewThingsILearned/archive/2008/08/22/calling-generic-method-when-given-a-type.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/NewThingsILearned/comments/commentRss/124628.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/NewThingsILearned/services/trackbacks/124628.aspx</trackback:ping>
        </item>
        <item>
            <title>Pack URI Authority - Local Assembly = Executable</title>
            <category>WPF</category>
            <category>.NET</category>
            <link>http://geekswithblogs.net/NewThingsILearned/archive/2008/04/30/pack-uri-authority---local-assembly--executable.aspx</link>
            <description>&lt;p&gt;I had a &lt;a href="http://geekswithblogs.net/NewThingsILearned/archive/2008/04/28/refer-to-resources-in-wpf-with-pack-uri.aspx"&gt;post&lt;/a&gt; about accessing XAML resources using Pack URI, and actually had the chance to try it out.  The format of the pack URI is "pack://authority/path", and there are only 2 valid authority: application:/// and siteoforigin:///, as described in &lt;a href="http://msdn.microsoft.com/en-us/library/aa970069.aspx"&gt;Microsoft's Pack URI documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The path will just point to the resource you want to get; you can include the folder / subfolder, other assemblies (containing the resource), even versions of the assembly.  The simplest example they had was:&lt;/p&gt;
&lt;p&gt;&lt;span class="code"&gt;pack://application:,,,/ResourceFile.xaml&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;that points to ResourceFile.xaml in the local assembly.  What the documentation forget to define however, is what is local assembly; the local assembly is essentially the WPF executable.  If you have other XAML in a different assembly, and you have code in that same assembly to load the XAML using Pack URI, you have to treat it as if you're loading from a different assembly.&lt;/p&gt;
&lt;p&gt;As an example, if you have a WPFResource.DLL which has a XAML resource (in this case test.xaml) you'd like to load, the code to load it will be as follows:&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;&lt;table cellspacing="1" cellpadding="1" width="600" summary="" border="1"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;private&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt"&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; InitializeWPFApplicationResources()&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;{&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;   &lt;span style="COLOR: #2b91af"&gt;Uri&lt;/span&gt; uri = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Uri&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"pack://application:,,,/WPFResource;component/test.xaml"&lt;/span&gt;);&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;   &lt;span style="COLOR: #2b91af"&gt;Application&lt;/span&gt;.Current.Resources.Source = uri;&lt;/span&gt;&lt;/div&gt;
            &lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;}&lt;/span&gt;&lt;/div&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt; The Pack URI has to refer to an external assembly - even though test.xaml resides in the same assembly with the executing code.  Anytime the pack URI doesn't refer to a different assembly, it will try to load the XAML resource from the executable file - I'm actually surprised with this, since it forces the Uri to always contain the assembly name which can be erroneous (say the assembly gets renamed).  Granted you can get around this problem by getting the assembly's name in code.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121792"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121792" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/NewThingsILearned/aggbug/121792.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Muljadi Budiman</dc:creator>
            <guid>http://geekswithblogs.net/NewThingsILearned/archive/2008/04/30/pack-uri-authority---local-assembly--executable.aspx</guid>
            <pubDate>Wed, 30 Apr 2008 16:02:50 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/NewThingsILearned/comments/121792.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/NewThingsILearned/archive/2008/04/30/pack-uri-authority---local-assembly--executable.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/NewThingsILearned/comments/commentRss/121792.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/NewThingsILearned/services/trackbacks/121792.aspx</trackback:ping>
        </item>
        <item>
            <title>Files downloaded by IE are marked Untrusted (or why the CHM file I downloaded didn't work)</title>
            <category>Windows</category>
            <link>http://geekswithblogs.net/NewThingsILearned/archive/2008/04/28/files-downloaded-by-ie-are-marked-untrusted-or-why-the.aspx</link>
            <description>&lt;p&gt;I downloaded a CHM (Windows help) file for &lt;a href="http://www.icsharpcode.com/OpenSource/SharpZipLib/Default.aspx"&gt;SharpZipLib&lt;/a&gt; software package to be used in my test app (pretty cool - allows me to do most stuff relating to zip files), and when I open the help file, none of the information shows.&lt;/p&gt;
&lt;p&gt;Of course when I tried to open it up, Windows always asks me to verify that I wanted to open the file, with the dialog below:&lt;/p&gt;
&lt;p&gt;&lt;img height="308" width="404" alt="" src="http://geekswithblogs.net/images/geekswithblogs_net/NewThingsILearned/UntrustedFile.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;However, even if I do allow this, the CHM file doesn't show its contents; the IE control that should display the help contents only show that the Program cannot display the webpage.  It turns out that this is a &lt;a href="http://support.microsoft.com/kb/902225"&gt;side effect of an IE security update&lt;/a&gt; - downloaded files are marked as untrusted and thus will require user's verification before it can be opened.  However, even if you verify for opening the files, the file itself is still marked untrusted, and as such IE will not allow rendering the information on the screen.&lt;/p&gt;
&lt;p&gt;To fix this, you'd have to mark the uncheck the 'Always ask before opening this file' checkbox, and you're good to go.  You can also go to the file's properties and click the Unblock button near the bottom.  This situation puzzles me for a few minutes before the light bulbs start switching on.  I'm pretty sure I will get this again in the future and be puzzled the same way &lt;img alt="" src="http://geekswithblogs.net/Providers/BlogEntryEditor/FCKeditor/editor/images/smiley/msn/regular_smile.gif" /&gt;.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121721"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121721" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/NewThingsILearned/aggbug/121721.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Muljadi Budiman</dc:creator>
            <guid>http://geekswithblogs.net/NewThingsILearned/archive/2008/04/28/files-downloaded-by-ie-are-marked-untrusted-or-why-the.aspx</guid>
            <pubDate>Mon, 28 Apr 2008 21:53:54 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/NewThingsILearned/comments/121721.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/NewThingsILearned/archive/2008/04/28/files-downloaded-by-ie-are-marked-untrusted-or-why-the.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/NewThingsILearned/comments/commentRss/121721.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/NewThingsILearned/services/trackbacks/121721.aspx</trackback:ping>
        </item>
        <item>
            <title>Refer to resources in WPF with Pack URI</title>
            <category>WPF</category>
            <category>.NET</category>
            <link>http://geekswithblogs.net/NewThingsILearned/archive/2008/04/28/refer-to-resources-in-wpf-with-pack-uri.aspx</link>
            <description>&lt;p&gt;It's been over 2 months since I last updated my blog.  I have been busy; we got a new VP of IT and he made some changes and there are a bunch of stuff that's getting rejigged and people moved, projects retargeted, etc. etc.  In the end, it's not enough reason for me to not blog at all.&lt;/p&gt;
&lt;p&gt;I started this blog so I can record my experiences with learning new stuff.  I have to say that I came back to this blog more than enough times to relook at the stuff I had learnt, to the point where my lapse in adding new stuff actually prevents me from being very productive - I learned some stuff that I should've put in here but I didn't, and in the end have to relearn it again since I didn't record it. D'uh.&lt;/p&gt;
&lt;p&gt;Anyway, I need to be more disciplined and will try to be more active.  Relearnt something today about how to access file resources in WPF, instead of using the typical StaticResource or DynamicResource - use Pack URIs, as further detailed &lt;a href="http://msdn2.microsoft.com/en-us/library/aa970069.aspx"&gt;here&lt;/a&gt;.  The 2 important ones for me to remember are referencing items in the same assembly and in a different assembly (use the following format with the Source attribute in xaml):&lt;/p&gt;
&lt;p&gt;pack://application:,,,/ResourceFile.xaml&lt;/p&gt;
&lt;p&gt;pack://application:,,,/ReferencedAssembly;component/ResourceFile.xaml&lt;/p&gt;
&lt;p&gt;This is actually very relevant to me; sometime last week, we had decided on trying to consolidate all our resources into a single DLL for each team project we have - it helps with internationalization (minimizing the number of DLLs), easier checking for entries that may already exist, can be used by other applications / modules if necessary, and can be swapped with another resource DLL or a newer one.&lt;/p&gt;
&lt;p&gt;With our application, we won't actually use the pack URI to point to different XAML (we may, but I see the use to be fairly limited in that regard), but we will use the pack URI to point to proper image / icon / bitmap files - so it's nice if we can consolidate all those files into a single DLL.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121717"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121717" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/NewThingsILearned/aggbug/121717.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Muljadi Budiman</dc:creator>
            <guid>http://geekswithblogs.net/NewThingsILearned/archive/2008/04/28/refer-to-resources-in-wpf-with-pack-uri.aspx</guid>
            <pubDate>Mon, 28 Apr 2008 18:41:44 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/NewThingsILearned/comments/121717.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/NewThingsILearned/archive/2008/04/28/refer-to-resources-in-wpf-with-pack-uri.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/NewThingsILearned/comments/commentRss/121717.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/NewThingsILearned/services/trackbacks/121717.aspx</trackback:ping>
        </item>
        <item>
            <title>Lambda Expression type inference doesn't quite work on actual methods</title>
            <category>.NET</category>
            <link>http://geekswithblogs.net/NewThingsILearned/archive/2008/02/13/lambda-expression-type-inference-doesnt-quite-work-on-actual-methods.aspx</link>
            <description>&lt;p&gt;One of the nice things with lambda expression is type inference - it is actually pretty neat.  A neat example that is as follows:&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;&lt;table cellspacing="1" cellpadding="1" width="600" summary="" border="1"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;private&lt;/span&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span style="COLOR: blue"&gt;void&lt;/span&gt;&lt;font color="#000000"&gt; Test()&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;font color="#000000"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font color="#000000"&gt;   &lt;/font&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;font color="#000000"&gt; original = &lt;/font&gt;&lt;span style="COLOR: #a31515"&gt;"Muljadi"&lt;/span&gt;&lt;font color="#000000"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font color="#000000"&gt;   &lt;/font&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;font color="#000000"&gt; upper = Demo(original, s =&amp;gt; s.ToUpper());&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font color="#000000"&gt;   &lt;/font&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;&lt;font color="#000000"&gt; length = Demo(original, s =&amp;gt; s.Length);&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;font color="#000000"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;private&lt;/span&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span style="COLOR: blue"&gt;static&lt;/span&gt;&lt;font color="#000000"&gt; TResult Demo&amp;lt;T, TResult&amp;gt;(T value, &lt;/font&gt;&lt;span style="COLOR: #2b91af"&gt;Func&lt;/span&gt;&lt;font color="#000000"&gt;&amp;lt;T, TResult&amp;gt; func)&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;font color="#000000"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font color="#000000"&gt;   &lt;/font&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;return&lt;/span&gt;&lt;font color="#000000"&gt; func(value);&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;In the example above, the first call to the Demo method has first parameter being a string - which then is immediately inferred to type T.  The compiler will also then infer that the second parameter is a lambda expression, which expects a single parameter, also of type T (which it has recognized as a string), walks thru the lambda expression and recognizes that it returns also a string.  As such, it determines that the first Demo method call will return a string and infer TResult as string.&lt;/p&gt;
&lt;p&gt;The second call to the Demo method follows the same path, and again when parsing the lambda expression, it will determine that it returns string.Length, which is of type &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; - it will then infer TResult as &lt;span style="COLOR: blue"&gt;int&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;However, I found out that the type inference doesn't work as nicely with actual methods.  The snippet below wouldn't work - I tried with as many combinations as possible, and I could not get it to work without actually creating an instance of the delegate.&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;&lt;table cellspacing="1" cellpadding="1" width="600" summary="" border="1"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;private&lt;/span&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span style="COLOR: blue"&gt;void&lt;/span&gt;&lt;font color="#000000"&gt; Test()&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;font color="#000000"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font color="#000000"&gt;   &lt;/font&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;font color="#000000"&gt; original = &lt;/font&gt;&lt;span style="COLOR: #a31515"&gt;"Muljadi"&lt;/span&gt;&lt;font color="#000000"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font color="#000000"&gt;   &lt;/font&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;&lt;font color="#000000"&gt; length = Demo(original, GetLength); &lt;/font&gt;&lt;span style="COLOR: green"&gt;// Type can't be inferred error&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;font color="#000000"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;length = Demo&amp;lt;&lt;/font&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;font color="#000000"&gt;, &lt;/font&gt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;&lt;font color="#000000"&gt;&amp;gt;(original, GetLength);&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;font color="#000000"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;length = Demo(original, &lt;/font&gt;&lt;span style="COLOR: blue"&gt;new&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span style="COLOR: #2b91af"&gt;Func&lt;/span&gt;&lt;font color="#000000"&gt;&amp;lt;&lt;/font&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;font color="#000000"&gt;, &lt;/font&gt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;&lt;font color="#000000"&gt;&amp;gt;(GetLength));&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;font color="#000000"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;length = Demo(original, s =&amp;gt; GetLength(s));&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;font color="#000000"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;private&lt;/span&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;&lt;font color="#000000"&gt; GetLength(&lt;/font&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;font color="#000000"&gt; s)&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;font color="#000000"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font color="#000000"&gt;   &lt;/font&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;return&lt;/span&gt;&lt;font color="#000000"&gt; s.Length;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;In my mind it just doesn't seem to make sense - the GetLength method is non-generic, has the return types and parameter type in the method and the compiler can't make sense of it.  The other 3 calls are valid because:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;You specify the type in the Demo method call itself&lt;/li&gt;
    &lt;li&gt;Your instantiate the method as a Func delegate, where you also specify the types&lt;/li&gt;
    &lt;li&gt;You actually make it as a lambda expression call&lt;/li&gt;
&lt;/ol&gt;
In the end, lambda expressions actually has better inference support than actual methods.  Hopefully Microsoft can add this in .NET 4.0.&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119556"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119556" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/NewThingsILearned/aggbug/119556.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Muljadi Budiman</dc:creator>
            <guid>http://geekswithblogs.net/NewThingsILearned/archive/2008/02/13/lambda-expression-type-inference-doesnt-quite-work-on-actual-methods.aspx</guid>
            <pubDate>Thu, 14 Feb 2008 00:47:18 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/NewThingsILearned/comments/119556.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/NewThingsILearned/archive/2008/02/13/lambda-expression-type-inference-doesnt-quite-work-on-actual-methods.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/NewThingsILearned/comments/commentRss/119556.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/NewThingsILearned/services/trackbacks/119556.aspx</trackback:ping>
        </item>
        <item>
            <title>Expensive Home theatre...</title>
            <category>Personal</category>
            <category>Home Theater</category>
            <link>http://geekswithblogs.net/NewThingsILearned/archive/2008/02/11/expensive-home-theatre.aspx</link>
            <description>&lt;p&gt;One of my hobby / passion is home theaters, and even though &lt;a href="http://blog.audiovideointeriors.com/208great/"&gt;$6 million&lt;/a&gt; is overkill, I thought I would brought it up as a good read &lt;img alt="" src="/Providers/BlogEntryEditor/FCKeditor/editor/images/smiley/msn/regular_smile.gif" /&gt;.  &lt;a href="http://blog.audiovideointeriors.com/208great/"&gt;Kipnis Studio Standard&lt;/a&gt;, 4096x2160 video, 18 ft screen, 8 speakers with 8 subs...&lt;/p&gt;
&lt;p&gt;The Sony Quad HD projector is one of interest to me - it costs $100K (if this &lt;a href="http://cgi.videogon.com/cgi-bin/cl.pl?projmisc&amp;amp;1178929326"&gt;post&lt;/a&gt; is to be believed) with NO lens (another $19K option give or take a couple of grand given what kind of lens you want), but I would like to see how an 8 megapixel image would look like on a big screen.&lt;/p&gt;
&lt;p&gt;Of course, the article doesn't talk about black level, contrast level, etc., but the equipment list is enough to make my mouth water.  My current ideal HT setup would be a &lt;a href="http://www.curtpalme.com/SonyG90.shtm"&gt;Sony G90&lt;/a&gt; with &lt;a href="http://www.dynaudio.com/eng/systems/lines/contour/contour_s_5_4.php"&gt;DynAudio Contour&lt;/a&gt; speakers (&lt;a href="http://www.velodyne.com/products/product.aspx?ID=3&amp;amp;sid=184q214r"&gt;Velodyne subs&lt;/a&gt;), driven with some nice amps (Mark Levinson, Krell, Plinius, etc.).  Most probably by the time I can afford these, my wife would insist on a small (read: digital) PJ, so current choices for me would be either JVC &lt;a href="http://pro.jvc.com/prof/attributes/features.jsp?model_id=MDL101681"&gt;RS-1&lt;/a&gt;/&lt;a href="http://pro.jvc.com/prof/attributes/features.jsp?model_id=MDL101733"&gt;RS-2&lt;/a&gt; (with a scaler that can do color control) or a &lt;a href="http://b2b.sony.com/Solutions/Solutions/product/VPL-VW200"&gt;Sony Diamond&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Perchance to dream...&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119452"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119452" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/NewThingsILearned/aggbug/119452.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Muljadi Budiman</dc:creator>
            <guid>http://geekswithblogs.net/NewThingsILearned/archive/2008/02/11/expensive-home-theatre.aspx</guid>
            <pubDate>Mon, 11 Feb 2008 15:45:03 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/NewThingsILearned/comments/119452.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/NewThingsILearned/archive/2008/02/11/expensive-home-theatre.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/NewThingsILearned/comments/commentRss/119452.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/NewThingsILearned/services/trackbacks/119452.aspx</trackback:ping>
        </item>
        <item>
            <title>My foray into Lambda Expressions</title>
            <category>.NET</category>
            <link>http://geekswithblogs.net/NewThingsILearned/archive/2008/02/11/my-foray-into-lambda-expressions.aspx</link>
            <description>&lt;p&gt;I was aware of lambda expressions because I was reading about them in the C# 3.0 white paper specification, along with other new language features like extension methods, anonymous types, basis for LINQ, etc.  I thought it was cool enough, it makes passing anonymous delegates much better in terms of code writing/reading.  However, actually using them takes a bit of getting used to.  As such, I'd like to give a short example as to how I visualize writing lambda expressions.&lt;/p&gt;
&lt;p&gt;Consider the following class structure representing a sports organization:&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;&lt;table cellspacing="1" cellpadding="1" width="600" summary="" border="1"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;public&lt;/span&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;League&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;&lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;Conference&lt;/span&gt;&amp;gt; _conferences;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;Conference&lt;/span&gt;&amp;gt; Conferences&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;      &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _conferences; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;public&lt;/span&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Conference&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;&lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;Division&lt;/span&gt;&amp;gt; _divisions;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;Division&lt;/span&gt;&amp;gt; Divisions&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;      &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _divisions; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;public&lt;/span&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Division&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;&lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;Team&lt;/span&gt;&amp;gt; _teams;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;Team&lt;/span&gt;&amp;gt; Teams&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;      &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _teams; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;public&lt;/span&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Team&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;&lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; _name;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; Name&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;      &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _name; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;}&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Basically, we have a League, which has a collection Conferences, which in turn have a collection of Divisions and each division having the Teams belonging to that division.  Let's say the task is to go collecting the names of all teams in the league - the code to do that is simple, you just loop through the conferences, loop through the division and then loop through the teams.  The code to do so will look like the following:&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;&lt;table cellspacing="1" cellpadding="1" width="600" summary="" border="1"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: #2b91af; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;List&lt;/span&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&amp;lt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&amp;gt; teamNames = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&amp;gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: #2b91af; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;League&lt;/span&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt; league = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;League&lt;/span&gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;foreach&lt;/span&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt; (&lt;span style="COLOR: #2b91af"&gt;Conference&lt;/span&gt; conference &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; league.Conferences)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;&lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (conference == &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;  &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;continue&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;&lt;span style="COLOR: blue"&gt;foreach&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;Division&lt;/span&gt; division &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; conference.Divisions)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;      &lt;/span&gt;&lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (division == &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;         &lt;/span&gt;&lt;span style="COLOR: blue"&gt;continue&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;      &lt;/span&gt;&lt;span style="COLOR: blue"&gt;foreach&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;Team&lt;/span&gt; team &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; division.Teams)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;      &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;         &lt;/span&gt;&lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (team == &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;            &lt;/span&gt;&lt;span style="COLOR: blue"&gt;continue&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;         &lt;/span&gt;teamNames.Add(team.Name);&lt;span style="mso-spacerun: yes"&gt;         &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;      &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The code above, it works, but it just seems mundane - you have multiple foreach loops, multiple null checks - it would be nice if we can refactor this somewhat.  So, we can create a method to refactor this - basically the method needs to be able to loop through a collection, check for null, and also do something else to the item being iterated.  In the code above, it needs to basically iterate through the inner collection twice (one for division and one for team), and when iterating through teams, it needs to add the team name to the collection (not iterate through).  With that pattern, a refactored method can be written as follows:&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;&lt;table cellspacing="1" cellpadding="1" width="600" summary="" border="1"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;private&lt;/span&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; ForEach&amp;lt;T&amp;gt;(&lt;span style="COLOR: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;T&amp;gt; enumerable, &lt;span style="COLOR: #2b91af"&gt;Action&lt;/span&gt;&amp;lt;T&amp;gt; action )&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;&lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (enumerable == &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;      &lt;/span&gt;&lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;&lt;span style="COLOR: blue"&gt;foreach&lt;/span&gt; (T item &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; enumerable)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;      &lt;/span&gt;action(item);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The method above will basically take an enumerable, checks to make sure it can enumerate it, and then loop through that enumerable and do something to the item being iterated - these 3 things satisfy the condition of the refactored method as mentioned above.  Now, that something that needs to be done is defined by the &lt;a href="http://msdn2.microsoft.com/en-us/library/018hxwa8.aspx"&gt;Action&amp;lt;T&amp;gt;&lt;/a&gt; delegate that the consumer of this function needs to specify.  So the above foreach loops can be written (using anonymouse delegates) as follows:&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;&lt;table cellspacing="1" cellpadding="1" width="600" summary="" border="1"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;ForEach(league.Conferences, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;Conference&lt;/span&gt; conf)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;ForEach(conf.Divisions, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;Division&lt;/span&gt; div) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;{ &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;      &lt;/span&gt;ForEach(div.Teams, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;Team&lt;/span&gt; team) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;      &lt;/span&gt;{ teamNames.Add(team.Name); });&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;});&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;});&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Well... it looks OK, but it's fairly unreadable - not to mention the developer needs to make sure everything ends properly, especially with the combination of the curly braces and the parentheses.  Enters Lamda expression, and the above code becomes like this instead:&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;&lt;table cellspacing="1" cellpadding="1" width="600" summary="" border="1"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;ForEach(league.Conferences,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;   &lt;/span&gt;conf =&amp;gt; ForEach(conf.Divisions,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;      &lt;/span&gt;div =&amp;gt; ForEach(div.Teams,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: &amp;quot;Courier New&amp;quot;; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;         &lt;/span&gt;team =&amp;gt; { &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (team != &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;) teamNames.Add(team.Name); })));&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Now, it is more compact, no question about it.  However, is it more readable?  Given the above example, assuming the developer knows what needs to be expected, it &lt;em&gt;may&lt;/em&gt; be more readable.  6 months from now if I were walking through the code, I would imagine it would take me awhile to read through that line - it requires knowing what the ForEach method does, it requires the developer to understood what the lambda expression is doing at each level, and it will be very hard to customize if the need arises.&lt;/p&gt;
&lt;p&gt;That said, I have to say I learned quite a bit from trying to refactor the above code into lambda expressions - it gives me a better understanding as to how to use them, how to refactor methods as lambda expressions, and also shows me a glimpse as to how they can be dangerous.  Most probably, I would make the last piece of logic (collecting the team name) to be its own function and pass that as a delegate, instead of writing the delegate in-line.  Two reasons for that:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;It's the portion where most probably will require logic changes (say not to add the team name if team name is empty, or has spaces, etc.)&lt;/li&gt;
    &lt;li&gt;It limits the consumer code to read like calling functions, so as I read through the code, I can understand it calls another piece of code (method) and I don't have to read the function definition in-line.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The above example is also a bit advanced since we're refactoring multiple foreach loops into a recursive delegate calls - take some time to make it sink through - it took me a good 2 hours to go through this the first time around.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119450"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119450" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/NewThingsILearned/aggbug/119450.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Muljadi Budiman</dc:creator>
            <guid>http://geekswithblogs.net/NewThingsILearned/archive/2008/02/11/my-foray-into-lambda-expressions.aspx</guid>
            <pubDate>Mon, 11 Feb 2008 15:16:50 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/NewThingsILearned/comments/119450.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/NewThingsILearned/archive/2008/02/11/my-foray-into-lambda-expressions.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/NewThingsILearned/comments/commentRss/119450.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/NewThingsILearned/services/trackbacks/119450.aspx</trackback:ping>
        </item>
    </channel>
</rss>