Still looking for a sponsor Max Paulousky is looking for a Silverlight/.Net job in the Commonwealth

Single-line Solution: Fibonacci number

As I mention in my previous post, next single-line function to implement is Fibonacci number. 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 Wikipedia) There are some variants to calculate Fibonacci number. First one is recursion: Func<int, int> fib = null; fib = n => (n < 2) ? 1 : fib(n-1) +...

Single-Line Solution: Factorial

Recently my colleagues started a dispute whether it is possible to calculate a factorial using just one line of code. In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. (by Wikipedia) One line means a line that ends with a semicolon: bla-bla-bla; Of course, following sample is not the single-row code: for(;;;) bla-bla-bla; First idea is using recursion (let’s arrange, it is the single-line...

How to get Xml InnerText in a Silverlight application – 2

There is an easier way to remove all xml tags from the document – regular expressions: Regex.Replace(text, @"<\/?[^>]*\/?>", string.Empty); Tagged: Silverlight , Xml , InnerText , Regular Expressions This work is licensed under a Creative Commons Attribution By license.

How to get Xml InnerText in a Silverlight application

The Silverlight framework is restricted in comparison with .Net framework. It does not provide the XmlDocument class, that has the InnerText property. Silverlight applications should use XDocument instead of XmlDocument. Following code is an extension method for the XNode class that implements InnerText functionality. public static string InnerText(this XNode xNode) { bool isContainer = xNode is XContainer; if (!isContainer) { switch (xNode.NodeType) ...