<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>C#</title>
        <link>http://www.maxpaulousky.com/blog/category/3.aspx</link>
        <description>C#</description>
        <language>en-US</language>
        <copyright>Max Paulousky</copyright>
        <generator>Subtext Version 2.1.2.2</generator>
        <item>
            <title>Single-line Solution: Fibonacci number</title>
            <link>http://www.maxpaulousky.com/blog/archive/2010/02/26/single-line-solution-fibonacci-number.aspx</link>
            <description>&lt;p&gt;As I mention in my previous &lt;a title="Single-Line Solution: Factorial" href="http://www.maxpaulousky.com/blog/archive/2010/02/25/single-line-solution-factorial.aspx" target="_blank"&gt;post&lt;/a&gt;, next single-line function to implement is Fibonacci number.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;By definition, the first two Fibonacci numbers are 0 and 1, and each remaining number is the sum of the previous two. Some sources omit the initial 0, instead beginning the sequence with two 1s. (by &lt;a title="Fibonacci number article" href="http://en.wikipedia.org/wiki/Fibonacci_number" target="_blank"&gt;Wikipedia&lt;/a&gt;)&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;There are some variants to calculate Fibonacci number. First one is recursion:&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;Func&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; fib = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;fib = n =&amp;gt; (n &amp;lt; 2) ? 1 : fib(n-1) + fib(n-2);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p /&gt;
As I show in the previous &lt;a title="Single-Line Solution: Factorial" href="http://www.maxpaulousky.com/blog/archive/2010/02/25/single-line-solution-factorial.aspx" target="_blank"&gt;post&lt;/a&gt;, this code can’t be a solution (nonsingle-line code). By the way, this code is absolutely inefficient. It has order of &lt;strong&gt;O(φ&lt;sup&gt;n&lt;/sup&gt;)&lt;/strong&gt; time complexity. 

&lt;p&gt;Next algorithm is computing Fibonacci number via its &lt;a title="Matrix form of Fibonacci number" href="http://en.wikipedia.org/wiki/Fibonacci_number#Matrix_form" target="_blank"&gt;matrix representation&lt;/a&gt;. This algorithm is very efficient (order of &lt;strong&gt;O(log&lt;sub&gt;2&lt;/sub&gt;n)&lt;/strong&gt; time complexity) but has great number of calculations (additions, multiplications, exponentiations). It will be difficult to understand such an &lt;a title="Calculating Fibonacci numbers (algorithms)" href="http://www.ics.uci.edu/~dan/class/161/notes/7/Fib.html" target="_blank"&gt;implementation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The best approach is the third variant. It is efficient enough &lt;strong&gt;O(n)&lt;/strong&gt; and has just two operation. The algorithm can be written as &lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;Fib2(n):&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;     i := 1&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;     j := 1&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;     &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; k := 3 to n &lt;span style="color: #0000ff"&gt;do&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        j := i+j&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        i := j-i&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; j&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p /&gt;

&lt;p&gt;This code can be implemented in C# 3.5, Linq as &lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; height: 35px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; fib = Enumerable.Range(1, n).Skip(2).Aggregate(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; KeyValuePair&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt;(1, 1), (seq, index) =&amp;gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; KeyValuePair&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt;(seq.Value, seq.Key + seq.Value)).Value;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Yes, it is quite long but it works!&lt;/p&gt;

&lt;p&gt;I create a range from 1 to n; skip first two elements (we know they values); store initial values in the KeyValuePair instance (1 and 1). In the aggregator function I repeat calculations as in the loop above.&lt;/p&gt;

&lt;p&gt;Can anyone implement the same functions using other programming languages and the single-line approach?&lt;/p&gt;

&lt;p&gt;Great discussion of Fibonacci numbers calculation using various programming languages is &lt;a title="Fibonacci numbers calculation discussion" href="http://www.hanselman.com/blog/TheWeeklySourceCode13FibonacciEdition.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That is it! &lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:8e38dbd1-7b32-4631-a5c8-030db9619ca3" class="wlWriterEditableSmartContent"&gt;&lt;div class="page_navigation navigation paginate pagination"&gt;     &lt;/div&gt;
&lt;p class="post_meta"&gt;
&lt;span&gt;Tagged: &lt;/span&gt;&lt;a href="http://www.maxpaulousky.com/blog/tags/C%23/default.aspx" rel="tag" title="View all posts in C#"&gt;C#&lt;/a&gt;
, &lt;a href="http://www.maxpaulousky.com/blog/tags/Recursion/default.aspx" rel="tag" title="View all posts in Recursion"&gt;Recursion&lt;/a&gt;
, &lt;a href="http://www.maxpaulousky.com/blog/tags/Single-Line+Code/default.aspx" rel="tag" title="View all posts in Single-Line Code"&gt;Single-Line Code&lt;/a&gt;
, &lt;a href="http://www.maxpaulousky.com/blog/tags/Linq/default.aspx" rel="tag" title="View all posts in Linq"&gt;Linq&lt;/a&gt;
, &lt;a href="http://www.maxpaulousky.com/blog/tags/Fibonacci/default.aspx" rel="tag" title="View all posts in Fibonacci"&gt;Fibonacci&lt;/a&gt;

&lt;/p&gt;&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;&lt;div class="post_license"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://www.maxpaulousky.com/blog/aggbug/27.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Max Paulousky</dc:creator>
            <guid>http://www.maxpaulousky.com/blog/archive/2010/02/26/single-line-solution-fibonacci-number.aspx</guid>
            <pubDate>Fri, 26 Feb 2010 21:45:28 GMT</pubDate>
            <wfw:comment>http://www.maxpaulousky.com/blog/comments/27.aspx</wfw:comment>
            <comments>http://www.maxpaulousky.com/blog/archive/2010/02/26/single-line-solution-fibonacci-number.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://www.maxpaulousky.com/blog/comments/commentRss/27.aspx</wfw:commentRss>
            <trackback:ping>http://www.maxpaulousky.com/blog/services/trackbacks/27.aspx</trackback:ping>
        </item>
        <item>
            <title>Single-Line Solution: Factorial</title>
            <link>http://www.maxpaulousky.com/blog/archive/2010/02/25/single-line-solution-factorial.aspx</link>
            <description>&lt;p&gt;Recently my colleagues started a dispute whether it is possible to calculate a factorial using just one line of code. &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;In mathematics, &lt;strong&gt;the factorial &lt;/strong&gt;of a non-negative integer &lt;strong&gt;n&lt;/strong&gt;, denoted by &lt;strong&gt;n!&lt;/strong&gt;, is the product of all positive integers less than or equal to &lt;strong&gt;n&lt;/strong&gt;. (by &lt;a title="Factorial - Wikipedia" href="http://en.wikipedia.org/wiki/Factorial" target="_blank"&gt;Wikipedia&lt;/a&gt;)&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;One line means a line that ends with a semicolon: &lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;bla-bla-bla;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p /&gt;

&lt;p&gt;Of course, following sample is not the single-row code:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;for&lt;/span&gt;(;;;) bla-bla-bla;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;First idea is using recursion (let’s arrange, it is the single-line code):&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;Func&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; factorial = n =&amp;gt; n &amp;lt; 2 ? 1 : n * factorial(n - 1);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; result = factorial(10);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
but it does not work (the &lt;font face="Courier New"&gt;factorial&lt;/font&gt; expression is not defined before evaluating the right side of the assignment).    &lt;p&gt;Following variant works but it is not the single-row solution (at least two code lines – &lt;font face="Courier New"&gt;factorial&lt;/font&gt; defining and initializing):&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;Func&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; factorial = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;factorial = n =&amp;gt; n &amp;lt; 2 ? 1 : n * factorial(n - 1);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; result = factorial(10);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p /&gt;

&lt;p&gt;The simplest variant of the single-line factorial calculating is&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; height: 52px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; factorial = Enumerable.Range(1, n).Aggregate((accumulator, next) =&amp;gt; accumulator * next);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p /&gt;

&lt;p /&gt;

&lt;p /&gt;

&lt;p /&gt;

&lt;p /&gt;

&lt;p /&gt;

&lt;p /&gt;

&lt;p&gt;The aggregate function takes the first element of the enumeration and put it into &lt;font face="Courier New"&gt;accumulator&lt;/font&gt;. Then it multiplies &lt;font face="Courier New"&gt;accumulator&lt;/font&gt; and next and put the result into &lt;font face="Courier New"&gt;accumulator&lt;/font&gt; again. Aggregate repeats the action for all elements. The result looks like&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;(....((((1 * 2) * 3) * 4) * 5) * .......) * n&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p /&gt;

&lt;p&gt;Next single-line solution I want to implement is a Fibonacci calculator.&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:a26aab29-977d-401c-a4c5-ec5c3abbc875" class="wlWriterEditableSmartContent"&gt;&lt;div class="page_navigation navigation paginate pagination"&gt;     &lt;/div&gt;
&lt;p class="post_meta"&gt;
&lt;span&gt;Tagged: &lt;/span&gt;&lt;a href="http://www.maxpaulousky.com/blog/tags/c%23/default.aspx" rel="tag" title="View all posts in c#"&gt;c#&lt;/a&gt;
, &lt;a href="http://www.maxpaulousky.com/blog/tags/Factorial/default.aspx" rel="tag" title="View all posts in Factorial"&gt;Factorial&lt;/a&gt;
, &lt;a href="http://www.maxpaulousky.com/blog/tags/Recursion/default.aspx" rel="tag" title="View all posts in Recursion"&gt;Recursion&lt;/a&gt;
, &lt;a href="http://www.maxpaulousky.com/blog/tags/Signle-Line+Code/default.aspx" rel="tag" title="View all posts in Signle-Line Code"&gt;Signle-Line Code&lt;/a&gt;
, &lt;a href="http://www.maxpaulousky.com/blog/tags/Linq/default.aspx" rel="tag" title="View all posts in Linq"&gt;Linq&lt;/a&gt;
, &lt;a href="http://www.maxpaulousky.com/blog/tags/Fibonacci/default.aspx" rel="tag" title="View all posts in Fibonacci"&gt;Fibonacci&lt;/a&gt;

&lt;/p&gt;&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;&lt;div class="post_license"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://www.maxpaulousky.com/blog/aggbug/26.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Max Paulousky</dc:creator>
            <guid>http://www.maxpaulousky.com/blog/archive/2010/02/25/single-line-solution-factorial.aspx</guid>
            <pubDate>Thu, 25 Feb 2010 21:09:26 GMT</pubDate>
            <wfw:comment>http://www.maxpaulousky.com/blog/comments/26.aspx</wfw:comment>
            <comments>http://www.maxpaulousky.com/blog/archive/2010/02/25/single-line-solution-factorial.aspx#feedback</comments>
            <wfw:commentRss>http://www.maxpaulousky.com/blog/comments/commentRss/26.aspx</wfw:commentRss>
            <trackback:ping>http://www.maxpaulousky.com/blog/services/trackbacks/26.aspx</trackback:ping>
        </item>
        <item>
            <title>How to get Xml InnerText in a Silverlight application &amp;ndash; 2</title>
            <link>http://www.maxpaulousky.com/blog/archive/2010/02/15/how-to-get-xml-innertext-in-a-silverlight-application-ndash.aspx</link>
            <description>&lt;p&gt;There is an easier way to remove all xml tags from the document – regular expressions:&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;Regex.Replace(text, &lt;span style="color: #006080"&gt;@"&amp;lt;\/?[^&amp;gt;]*\/?&amp;gt;"&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Empty); &lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p /&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e22905bb-1e00-4909-84f8-460e30aeec32" class="wlWriterEditableSmartContent"&gt;&lt;div class="page_navigation navigation paginate pagination"&gt;     &lt;/div&gt;
&lt;p class="post_meta"&gt;
&lt;span&gt;Tagged: &lt;/span&gt;&lt;a href="http://www.maxpaulousky.com/blog/tags/Silverlight/default.aspx" rel="tag" title="View all posts in Silverlight"&gt;Silverlight&lt;/a&gt;
, &lt;a href="http://www.maxpaulousky.com/blog/tags/Xml/default.aspx" rel="tag" title="View all posts in Xml"&gt;Xml&lt;/a&gt;
, &lt;a href="http://www.maxpaulousky.com/blog/tags/InnerText/default.aspx" rel="tag" title="View all posts in InnerText"&gt;InnerText&lt;/a&gt;
, &lt;a href="http://www.maxpaulousky.com/blog/tags/Regular+Expressions/default.aspx" rel="tag" title="View all posts in Regular Expressions"&gt;Regular Expressions&lt;/a&gt;

&lt;/p&gt;&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;&lt;div class="post_license"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://www.maxpaulousky.com/blog/aggbug/22.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Max Paulousky</dc:creator>
            <guid>http://www.maxpaulousky.com/blog/archive/2010/02/15/how-to-get-xml-innertext-in-a-silverlight-application-ndash.aspx</guid>
            <pubDate>Mon, 15 Feb 2010 19:40:05 GMT</pubDate>
            <wfw:comment>http://www.maxpaulousky.com/blog/comments/22.aspx</wfw:comment>
            <comments>http://www.maxpaulousky.com/blog/archive/2010/02/15/how-to-get-xml-innertext-in-a-silverlight-application-ndash.aspx#feedback</comments>
            <wfw:commentRss>http://www.maxpaulousky.com/blog/comments/commentRss/22.aspx</wfw:commentRss>
            <trackback:ping>http://www.maxpaulousky.com/blog/services/trackbacks/22.aspx</trackback:ping>
        </item>
        <item>
            <title>How to get Xml InnerText in a Silverlight application</title>
            <link>http://www.maxpaulousky.com/blog/archive/2010/01/30/innertext-for-silverlight-applications.aspx</link>
            <description>&lt;p&gt;The Silverlight framework is restricted in comparison with .Net framework. It does not provide the &lt;font color="#400000" face="Courier New"&gt;XmlDocument&lt;/font&gt; class, that has the &lt;font face="Courier New"&gt;InnerText&lt;/font&gt; property. Silverlight applications should use &lt;font face="Courier New"&gt;XDocument&lt;/font&gt; instead of &lt;font color="#400000" face="Courier New"&gt;XmlDocument&lt;/font&gt;. Following code is an extension method for the &lt;font face="Courier New"&gt;XNode&lt;/font&gt; class that implements &lt;font face="Courier New"&gt;InnerText&lt;/font&gt; functionality.&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; height: 432px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; InnerText(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt; XNode xNode)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; isContainer = xNode &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; XContainer;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!isContainer)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;  {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;switch&lt;/span&gt; (xNode.NodeType)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; XmlNodeType.Text:&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; XmlNodeType.CDATA:&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; XmlNodeType.Whitespace:&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; XmlNodeType.SignificantWhitespace:&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; xNode.ToString();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;default&lt;/span&gt;:&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Empty;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;  }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;  {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    XContainer xContainer = (XContainer)xNode;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    StringBuilder sb = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; StringBuilder();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (XNode node = xContainer.FirstNode; node != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;; node = node.NextNode)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;      sb.Append(node.InnerText());&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; sb.ToString();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;  }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;font color="#400000" face="Courier New"&gt;XContainer&lt;/font&gt; is a type of xml nodes that contain child nodes and they should be processed recursively. &lt;/p&gt;

&lt;p /&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:afad21ec-6a3d-44a1-83b1-5a58a5f1264e" class="wlWriterEditableSmartContent"&gt;&lt;div class="page_navigation navigation paginate pagination"&gt;     &lt;/div&gt;
&lt;p class="post_meta"&gt;
&lt;span&gt;Tagged: &lt;/span&gt;&lt;a href="http://www.maxpaulousky.com/blog/tags/Silverlight/default.aspx" rel="tag" title="View all posts in Silverlight"&gt;Silverlight&lt;/a&gt;
, &lt;a href="http://www.maxpaulousky.com/blog/tags/Xml/default.aspx" rel="tag" title="View all posts in Xml"&gt;Xml&lt;/a&gt;
, &lt;a href="http://www.maxpaulousky.com/blog/tags/XDocument/default.aspx" rel="tag" title="View all posts in XDocument"&gt;XDocument&lt;/a&gt;
, &lt;a href="http://www.maxpaulousky.com/blog/tags/XNode/default.aspx" rel="tag" title="View all posts in XNode"&gt;XNode&lt;/a&gt;
, &lt;a href="http://www.maxpaulousky.com/blog/tags/InnerText/default.aspx" rel="tag" title="View all posts in InnerText"&gt;InnerText&lt;/a&gt;

&lt;/p&gt;&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;&lt;div class="post_license"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://www.maxpaulousky.com/blog/aggbug/20.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Max Paulousky</dc:creator>
            <guid>http://www.maxpaulousky.com/blog/archive/2010/01/30/innertext-for-silverlight-applications.aspx</guid>
            <pubDate>Sat, 30 Jan 2010 13:07:37 GMT</pubDate>
            <wfw:comment>http://www.maxpaulousky.com/blog/comments/20.aspx</wfw:comment>
            <comments>http://www.maxpaulousky.com/blog/archive/2010/01/30/innertext-for-silverlight-applications.aspx#feedback</comments>
            <wfw:commentRss>http://www.maxpaulousky.com/blog/comments/commentRss/20.aspx</wfw:commentRss>
            <trackback:ping>http://www.maxpaulousky.com/blog/services/trackbacks/20.aspx</trackback:ping>
        </item>
    </channel>
</rss>
