<feed version="0.3" 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="http://purl.org/atom/ns#" xml:lang="en-US"><title>Anatoly Lubarsky</title><link rel="alternate" type="text/html" href="http://blogs.x2line.com/al/" /><tagline type="text/html">MSSQL, .NET, Design. Life and Music </tagline><id>http://blogs.x2line.com/al/</id><author><name>Anatoly Lubarsky</name><url>http://blogs.x2line.com/al/</url></author><generator url="http://blogs.x2line.com/" version="Version 0.97.2006.1">http://blogs.x2line.com/</generator><modified>2008-05-09T22:59:00Z</modified><entry><title>T-SQL: LIKE Operator and Wildcard Characters</title><link rel="alternate" type="text/html" href="http://blogs.x2line.com/al/archive/2008/05/08/3420.aspx" /><id>http://blogs.x2line.com/al/archive/2008/05/08/3420.aspx</id><created>2008-05-08T02:37:00Z</created><issued>2008-05-08T00:37:00+02:00</issued><modified>2008-05-08T02:39:00Z</modified><summary type="text/html">An interesting issue I came into recently. Suppose you have a search procedure - which consists of some SELECT query which gets a query phrase as a parameter and searches through a table coulumn using LIKE [ ... ]</summary><content type="text/html" mode="escaped">&lt;p&gt;An interesting issue I came into recently. Suppose you have a search procedure - which consists of some SELECT query which gets a query phrase as a parameter and searches through a table column using LIKE.&lt;/p&gt;&lt;br&gt;
&lt;p&gt;The most common pattern is to add % at the beginning and the end of the search parameter so the query looks like so:&lt;/p&gt;&lt;br&gt;
&lt;pre&gt;WHERE Col LIKE '%' + @param + '%'
&lt;/pre&gt;&lt;br&gt;
&lt;p&gt;Or you may perform concatenation before running the query as well :) However need to take into account the following. The search parameter which usually comes down to the procedure from the application user interface can contain T-SQL reserved wildcard characters such as =&amp;gt; % [ ] _ etc. Such input will cause the query to return wrong results.&lt;/p&gt;&lt;br&gt;
&lt;p&gt;Therefore it is useful to remember to filter out or replace these characters so MSSQL will consider these characters literals. For example if we have rectangular braces =&amp;gt; [], need to replace the opening brace =&amp;gt; [ with the sequence =&amp;gt; [[] before running the query.&lt;/p&gt;&lt;img src ="http://blogs.x2line.com/al/aggbug/3420.aspx" width = "1" height = "1" /&gt;</content><wfw:comment>http://blogs.x2line.com/al/comments/3420.aspx</wfw:comment><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.x2line.com/al/comments/commentRss/3420.aspx</wfw:commentRss><trackback:ping>http://blogs.x2line.com/al/services/trackbacks/3420.aspx</trackback:ping></entry><entry><title>MSSQL: Search and Replace in a TEXT(NTEXT) column</title><link rel="alternate" type="text/html" href="http://blogs.x2line.com/al/archive/2008/05/03/3417.aspx" /><id>http://blogs.x2line.com/al/archive/2008/05/03/3417.aspx</id><created>2008-05-03T20:16:00Z</created><issued>2008-05-03T18:16:00+02:00</issued><modified>2008-05-03T20:16:00Z</modified><summary type="text/html">Sometimes we need to search and replace a text value in the entire table. The column in question is of TEXT or NTEXT datatype. T-SQL REPLACE function does not work with TEXT/NTEXT datatype. Instead we have to use several other functions [ ... ]</summary><content type="text/html" mode="escaped">&lt;p&gt;It's been a while since I've posted anything SQL related. So... Sometimes we need to search and replace a text value in the entire table. The column in question is of TEXT or NTEXT datatype. T-SQL REPLACE function does not work with TEXT/NTEXT datatype.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Instead we have to use several other functions:&lt;/p&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;UPDATETEXT&lt;/b&gt; - Updates an existing text, ntext, or image field.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;TEXTPTR&lt;/b&gt; - Returns the text-pointer value that corresponds to a text, ntext, or image column in varbinary format. The retrieved text pointer value can be used in READTEXT, WRITETEXT, and UPDATETEXT statements.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;PATINDEX&lt;/b&gt; - Returns the starting position of the first occurrence of a pattern in a specified expression, or zeros if the pattern is not found, on all valid text and character data types.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;p&gt;A while ago I wrote a small utility procedure which uses above functions to implement Search and Replace functionality.&lt;/p&gt;&lt;br /&gt;
&lt;pre&gt;
ALTER PROC dbo.SearchAndReplace 
(
     @FindString    NVARCHAR(100)
    ,@ReplaceString NVARCHAR(100)
)
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @TextPointer VARBINARY(16) 
    DECLARE @DeleteLength INT 
    DECLARE @OffSet INT 

    SELECT @TextPointer = TEXTPTR([MY_TEXT_COLUMN])
      FROM [MY_TABLE]

    SET @DeleteLength = LEN(@FindString) 
    SET @OffSet = 0
    SET @FindString = '%' + @FindString + '%'

    WHILE (SELECT COUNT(*)
             FROM [MY_TABLE]
            WHERE PATINDEX(@FindString, [MY_TEXT_COLUMN]) &lt;&gt; 0) &gt; 0
    BEGIN 
        SELECT @OffSet = PATINDEX(@FindString, [MY_TEXT_COLUMN]) - 1
          FROM [MY_TABLE]
         WHERE PATINDEX(@FindString, [MY_TEXT_COLUMN]) &lt;&gt; 0

        UPDATETEXT [MY_TABLE].[MY_TEXT_COLUMN]
            @TextPointer
            @OffSet
            @DeleteLength
            @ReplaceString
    END

    SET NOCOUNT OFF
END
&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;Hope this helps...&lt;/p&gt;&lt;img src ="http://blogs.x2line.com/al/aggbug/3417.aspx" width = "1" height = "1" /&gt;</content><wfw:comment>http://blogs.x2line.com/al/comments/3417.aspx</wfw:comment><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.x2line.com/al/comments/commentRss/3417.aspx</wfw:commentRss><trackback:ping>http://blogs.x2line.com/al/services/trackbacks/3417.aspx</trackback:ping></entry><entry><title>Facebook's Standard Security Settings Sufficient ? (Not)</title><link rel="alternate" type="text/html" href="http://blogs.x2line.com/al/archive/2008/05/02/3412.aspx" /><id>http://blogs.x2line.com/al/archive/2008/05/02/3412.aspx</id><created>2008-05-02T04:43:00Z</created><issued>2008-05-02T02:43:00+02:00</issued><modified>2008-05-02T04:47:00Z</modified><summary type="text/html">BBC came out with an article today Identity 'at risk' on Facebook which discusses potential stealing of user data by 3rd parties applications of Facebook Development Platform: When you add an application [ ... ]</summary><content type="text/html" mode="escaped">&lt;p&gt;BBC came out with an article today &lt;a href="http://news.bbc.co.uk/2/hi/programmes/click_online/7375772.stm" target="_blank"&gt;Identity 'at risk' on Facebook&lt;/a&gt; which discusses potential stealing of user data by 3rd parties applications of Facebook Development Platform:&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;i&gt;"When you add an application, unless you say otherwise, it is given access to most of the information in your profile. That includes information you have on your friends even if they think they have tight security settings."&lt;/i&gt;&lt;/p&gt;&lt;br /&gt; 
&lt;p&gt;&lt;i&gt;"Did you know that you were responsible for other people's security?"&lt;/i&gt;&lt;/p&gt;&lt;br&gt;
&lt;p&gt;Some Facebook applications developers have found this article misleading and "hilarious" - see the following thread: &lt;a href="http://forum.developers.facebook.com/viewtopic.php?id=14274" target="_blank"&gt;BBC: facebook apps dangerous&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;However I find the article to be professional and points discussed there to be correct and valuable for the platform.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;One important point developers missing is that the application in question is able to collect user friends data, while these friends are not aware of this application existing at all. No obvious OPT-IN for "friends".&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Your friends don't need to install the application or ever login to it to have the info been collected.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Of course it is possible to not allow applications you haven't installed to get any info at all via user "Privacy Settings" page. Don't want to mention it is not obvious for the user he/she should do it. But are these settings secure "by default" ? I guess - no.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The BBC article points that out correctly:&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;i&gt;"He said: "Facebook needs to change its default settings and tighten up security.""&lt;/i&gt;&lt;/p&gt;&lt;br&gt;
&lt;p&gt;"Default Settings" is very important security component of any system or application. In terms of "Default Settings" the good example is Internet Explorer. Think about how many default settings changes have been made in IE during recent years.&lt;/p&gt;&lt;img src ="http://blogs.x2line.com/al/aggbug/3412.aspx" width = "1" height = "1" /&gt;</content><wfw:comment>http://blogs.x2line.com/al/comments/3412.aspx</wfw:comment><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.x2line.com/al/comments/commentRss/3412.aspx</wfw:commentRss><trackback:ping>http://blogs.x2line.com/al/services/trackbacks/3412.aspx</trackback:ping></entry><entry><title>ASP.NET tip: Autonumber Rows in ASP.NET Repeater control</title><link rel="alternate" type="text/html" href="http://blogs.x2line.com/al/archive/2008/04/26/3408.aspx" /><id>http://blogs.x2line.com/al/archive/2008/04/26/3408.aspx</id><created>2008-04-26T02:37:00Z</created><issued>2008-04-26T00:37:00+02:00</issued><modified>2008-04-26T04:08:00Z</modified><summary type="text/html">How to print the current row number in an ASP.NET Repeater control ? The easiest way to autonumber rows in Repeater is to use markup or ItemDataBound event [ ... ]</summary><content type="text/html" mode="escaped">&lt;p&gt;Q: How to print the current row number in an ASP.NET Repeater control ?&lt;/p&gt;&lt;br&gt;
&lt;p&gt;A: The easiest way to autonumber rows in Repeater is to use markup or ItemDataBound event. Since each row has ItemIndex property when created/bounded. Therefore for Repeater markup one can write the following:&lt;/p&gt;&lt;br /&gt;
&lt;pre&gt;
&lt; ItemTemplate&gt;
    &lt; %# Container.ItemIndex + 1 %&gt;
&lt; /ItemTemplate&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;Or in the ItemDataBound event (for more complex rendering) this should look like so:&lt;/p&gt;&lt;br /&gt;
&lt;pre&gt;
if ((e.Item.ItemType == ListItemType.AlternatingItem) || 
    (e.Item.ItemType == ListItemType.Item))
{
    int num = e.Item.ItemIndex + 1;

    // some code
}
&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;Enjoy :)&lt;/p&gt;&lt;img src ="http://blogs.x2line.com/al/aggbug/3408.aspx" width = "1" height = "1" /&gt;</content><wfw:comment>http://blogs.x2line.com/al/comments/3408.aspx</wfw:comment><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.x2line.com/al/comments/commentRss/3408.aspx</wfw:commentRss><trackback:ping>http://blogs.x2line.com/al/services/trackbacks/3408.aspx</trackback:ping></entry><entry><title>Bathroom Stall Vandalism - 2000 Users on BEBO</title><link rel="alternate" type="text/html" href="http://blogs.x2line.com/al/archive/2008/04/22/3405.aspx" /><id>http://blogs.x2line.com/al/archive/2008/04/22/3405.aspx</id><created>2008-04-22T19:47:00Z</created><issued>2008-04-22T17:47:00+02:00</issued><modified>2008-04-22T19:47:00Z</modified><summary type="text/html">Bathroom Stall Vandalism on BEBO&lt;/a&gt; has passed 2000 users [ ... ]</summary><content type="text/html" mode="escaped">&lt;p&gt;&lt;img src="http://photos-285.ll.facebook.com/photos-ll-sctm/v43/133/5180194285/app_3_5180194285_4392.gif" alt="Bathroom Stall Vandalism" /&gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://www.bebo.com/Profile.jsp?MemberId=5409925639"&gt;Bathroom Stall Vandalism on BEBO&lt;/a&gt; has passed 2000 users. Which is good stats for the application with zero investment (just scaling up from facebook). Around 10% of them are active daily.&lt;/p&gt;&lt;img src ="http://blogs.x2line.com/al/aggbug/3405.aspx" width = "1" height = "1" /&gt;</content><wfw:comment>http://blogs.x2line.com/al/comments/3405.aspx</wfw:comment><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.x2line.com/al/comments/commentRss/3405.aspx</wfw:commentRss><trackback:ping>http://blogs.x2line.com/al/services/trackbacks/3405.aspx</trackback:ping></entry><entry><title>Reducing Memory Footprint of any Process with EmptyWorkingSet</title><link rel="alternate" type="text/html" href="http://blogs.x2line.com/al/archive/2008/04/20/3394.aspx" /><id>http://blogs.x2line.com/al/archive/2008/04/20/3394.aspx</id><created>2008-04-20T21:07:00Z</created><issued>2008-04-20T19:07:00+02:00</issued><modified>2008-04-20T21:07:00Z</modified><summary type="text/html">Ever wondered why does .NET winform application takes so much memory on startup ? It is obvious that most of this memory is not in use. The reason is that JIT compiler and the whole winforms engine is loaded into the process [ ... ]</summary><content type="text/html" mode="escaped">&lt;p&gt;Ever wondered why does .NET winform application takes so much memory on startup ? It is obvious that most of this memory is not in use. The reason is that JIT compiler and the whole winforms engine is loaded into the process. However it is possible to remove as many pages as possible from the working set of the specified process using &lt;i&gt;EmptyWorkingSet&lt;/i&gt; from &lt;b&gt;psapi.dll&lt;/b&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;pre&gt;
[DllImport("psapi.dll")]
static extern int EmptyWorkingSet(IntPtr hwProc);
&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;From managed code we can use it  like so (for the current process):&lt;/p&gt;&lt;br /&gt;
&lt;pre&gt;
static void ClearMemory()
{
    EmptyWorkingSet(Process.GetCurrentProcess().Handle);
}
&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;However it is possible to use this function for any process which handle must have the PROCESS_QUERY_INFORMATION and PROCESS_SET_INFORMATION access rights. Be careful using EmptyWorkingSet since the process will allocate the memory again in the future when needed.&lt;/p&gt;&lt;img src ="http://blogs.x2line.com/al/aggbug/3394.aspx" width = "1" height = "1" /&gt;</content><wfw:comment>http://blogs.x2line.com/al/comments/3394.aspx</wfw:comment><slash:comments>3</slash:comments><wfw:commentRss>http://blogs.x2line.com/al/comments/commentRss/3394.aspx</wfw:commentRss><trackback:ping>http://blogs.x2line.com/al/services/trackbacks/3394.aspx</trackback:ping></entry><entry><title>C# Win32 API: Flash Window (FlashWindowEx)</title><link rel="alternate" type="text/html" href="http://blogs.x2line.com/al/archive/2008/04/19/3392.aspx" /><id>http://blogs.x2line.com/al/archive/2008/04/19/3392.aspx</id><created>2008-04-19T21:11:00Z</created><issued>2008-04-19T19:11:00+02:00</issued><modified>2008-04-19T21:16:00Z</modified><summary type="text/html">he following method will flash the title bar or taskbar button or tray icon. Need to wrap a method imported from user32: FlashWindowEx [ ... ]</summary><content type="text/html" mode="escaped">&lt;p&gt;Ever tried to flash a window using managed code ? The following method will flash the window title bar or the window taskbar button. Since there is no managed API available for this functionality - need to wrap a method imported from user32: &lt;i&gt;FlashWindowEx&lt;/i&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;pre&gt;
[DllImport("user32.dll")]
static extern Int32 FlashWindowEx(ref FLASHWINFO pwfi);
&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;Where FLASHWINFO struct is defined like so:&lt;/p&gt;&lt;br /&gt;
&lt;pre&gt;
[StructLayout(LayoutKind.Sequential)]
public struct FLASHWINFO
{
    public UInt32 cbSize;
    public IntPtr hwnd;
    public Int32 dwFlags;
    public UInt32 uCount;
    public Int32 dwTimeout;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;Where &lt;i&gt;dwFlags&lt;/i&gt; can be one of the following:&lt;/p&gt;&lt;br /&gt;
&lt;pre&gt;
// stop flashing
FLASHW_STOP = 0; 

// flash the window title 
FLASHW_CAPTION = 1; 

// flash the taskbar button
FLASHW_TRAY = 2; 

// 1 | 2
FLASHW_ALL = 3; 

// flash continuously 
FLASHW_TIMER = 4; 

// flash until the window comes to the foreground 
FLASHW_TIMERNOFG = 12; 
&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;So the typical C# call will look like so:&lt;/p&gt;&lt;br /&gt;
&lt;pre&gt;
public static bool Flash()
{
    FLASHWINFO fw = new FLASHWINFO();

    fw.cbSize = Convert.ToUInt32(Marshal.SizeOf(typeof(FLASHWINFO)));
    fw.hwnd = this.Handle;
    fw.dwFlags = 2;
    fw.uCount = UInt32.MaxValue;

    FlashWindowEx(ref fw);
}
&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;See some other &lt;a href="http://blogs.x2line.com/al/category/95.aspx"&gt;C# Win32 API tips and tricks&lt;/a&gt;. Enjoy :)&lt;/p&gt;&lt;img src ="http://blogs.x2line.com/al/aggbug/3392.aspx" width = "1" height = "1" /&gt;</content><wfw:comment>http://blogs.x2line.com/al/comments/3392.aspx</wfw:comment><slash:comments>1</slash:comments><wfw:commentRss>http://blogs.x2line.com/al/comments/commentRss/3392.aspx</wfw:commentRss><trackback:ping>http://blogs.x2line.com/al/services/trackbacks/3392.aspx</trackback:ping></entry><entry><title>Thoughts on Bebo Audience</title><link rel="alternate" type="text/html" href="http://blogs.x2line.com/al/archive/2008/04/10/3384.aspx" /><id>http://blogs.x2line.com/al/archive/2008/04/10/3384.aspx</id><created>2008-04-10T02:17:00Z</created><issued>2008-04-10T00:17:00+02:00</issued><modified>2008-04-10T02:17:00Z</modified><summary type="text/html">Since one of my applications - Bathroom Stall Vandalism works both on bebo and on facebook as well - it is always useful to compare performance on both platforms. BTW, Bathroom Stall Vandalism is all about people virtually write and vandalize their rest rooms (LOL) [ ... ]</summary><content type="text/html" mode="escaped">&lt;p&gt;Since one of my applications - Bathroom Stall Vandalism works both on &lt;a href="http://www.bebo.com/Profile.jsp?MemberId=5409925639"&gt;bebo&lt;/a&gt; and on &lt;a href="http://www.facebook.com/applications/Bathroom_Stall_Vandalism/5180194285"&gt;facebook&lt;/a&gt; as well - it is always useful to compare performance on both platforms. BTW, Bathroom Stall Vandalism is all about people virtually write and vandalize their rest rooms (LOL).&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Need to take in to account that:&lt;/p&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Bebo uses facebook's API model for its platform.&lt;/li&gt;
&lt;li&gt;Facebook platform is more stable right now.&lt;/li&gt;
&lt;li&gt;Facebook platform is more mature and much more competitive.&lt;/li&gt;
&lt;li&gt;The app has the same canvas and database.&lt;/li&gt;
&lt;li&gt;Bathroom Stall Vandalism was initially launched on facebook during october/november 2007 and was scaled up to support bebo in january 2008.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://www.flickr.com/photos/60703797@N00/2402070300/" title="Bathroom Stall Vandalism - Facebook vs. Bebo"&gt;&lt;img src="http://farm3.static.flickr.com/2107/2402070300_34ea07a8dc.jpg" alt="Bathroom Stall Vandalism - Facebook vs. Bebo" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;One can understand from the screenshot that the app is more popular among bebo users: they spend more time on site, have better bounce rate, etc.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Bebo audience is very special: most users are under 18 from UK, Australia and New Zealand.&lt;/p&gt;&lt;img src ="http://blogs.x2line.com/al/aggbug/3384.aspx" width = "1" height = "1" /&gt;</content><wfw:comment>http://blogs.x2line.com/al/comments/3384.aspx</wfw:comment><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.x2line.com/al/comments/commentRss/3384.aspx</wfw:commentRss><trackback:ping>http://blogs.x2line.com/al/services/trackbacks/3384.aspx</trackback:ping></entry><entry><title>Back from Thailand 2</title><link rel="alternate" type="text/html" href="http://blogs.x2line.com/al/archive/2008/04/04/3381.aspx" /><id>http://blogs.x2line.com/al/archive/2008/04/04/3381.aspx</id><created>2008-04-04T19:47:00Z</created><issued>2008-04-04T17:47:00+02:00</issued><modified>2008-04-04T19:47:00Z</modified><summary type="text/html">Patong Beach, Phuket, Thailand. March 2008 [ ... ]</summary><content type="text/html" mode="escaped">&lt;p&gt;I'm back again from Thailand.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://www.flickr.com/photos/60703797@N00/2386532939/"&gt;&lt;img src="http://farm4.static.flickr.com/3182/2386532939_336834854a.jpg" alt="anatoly" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The picture above is taken from Patong Beach, Phuket, Thailand.&lt;/p&gt;&lt;img src ="http://blogs.x2line.com/al/aggbug/3381.aspx" width = "1" height = "1" /&gt;</content><wfw:comment>http://blogs.x2line.com/al/comments/3381.aspx</wfw:comment><slash:comments>2</slash:comments><wfw:commentRss>http://blogs.x2line.com/al/comments/commentRss/3381.aspx</wfw:commentRss><trackback:ping>http://blogs.x2line.com/al/services/trackbacks/3381.aspx</trackback:ping></entry><entry><title>Calculate Euler Number with Recursion</title><link rel="alternate" type="text/html" href="http://blogs.x2line.com/al/archive/2008/03/11/3377.aspx" /><id>http://blogs.x2line.com/al/archive/2008/03/11/3377.aspx</id><created>2008-03-11T04:01:00Z</created><issued>2008-03-11T02:01:00+02:00</issued><modified>2008-03-11T20:24:00Z</modified><summary type="text/html">I recently went through several posts I had made on one of the development forums back then in 2005. I've found one of them interesting and want to repost it here. The question went like this: How can I calculate euler number with recursion [ ... ]</summary><content type="text/html" mode="escaped">&lt;p&gt;I recently went through several posts I had made on one of the development forums back then in 2005. I've found one of them interesting and wanted to repost it here. The question went like this:&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;i&gt;"How can I calculate euler number with recursion ?"&lt;/i&gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/E_%28mathematical_constant%29" target="_blank"&gt;Euler number&lt;/a&gt; (or &lt;b&gt;e&lt;/b&gt;) can be calculated with the following formula in math:&lt;/p&gt;&lt;br /&gt;
&lt;pre&gt;sum = 1/0! + 1/1! + 1/2! + ... + 1/n!&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;Here one can notice the use of the Factorial function which can be implemented via recursion itself  like so:&lt;/p&gt;&lt;br /&gt;
&lt;pre&gt;
int Factorial(int n) 
{
    if (n == 0) 
    {
        return 1;
    }

    return n * Factorial(n - 1);
}
&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;After we know how to implement Factorial we can implement &lt;b&gt;Euler number&lt;/b&gt; using recursion as well:&lt;/p&gt;&lt;br /&gt;
&lt;pre&gt;
double EulerNumber(int n) 
{
    if (n == 0) 
    {
        return 1;
    }

    return 1.0/Factorial(n) + EulerNumber(n - 1);
}
&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;Enjoy :)&lt;/p&gt;&lt;img src ="http://blogs.x2line.com/al/aggbug/3377.aspx" width = "1" height = "1" /&gt;</content><wfw:comment>http://blogs.x2line.com/al/comments/3377.aspx</wfw:comment><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.x2line.com/al/comments/commentRss/3377.aspx</wfw:commentRss><trackback:ping>http://blogs.x2line.com/al/services/trackbacks/3377.aspx</trackback:ping></entry></feed>