<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7812923111809291334</id><updated>2024-10-24T03:33:20.170-04:00</updated><category term="C#"/><category term="Project Euler"/><category term="F#"/><category term="JavaScript"/><category term="AngularJS"/><category term="Design Patterns"/><category term="HTML"/><category term="MVC4"/><category term="ASP.net"/><category term="Angular"/><category term="Angular Directives"/><category term="Angular Services"/><category term="Bundle"/><category term="Bundling"/><category term="C# 6.0"/><category term="CSS"/><category term="DI"/><category term="Dependency Injection"/><category term="DisplateTemplates"/><category term="EditorTemplates"/><category term="Experience"/><category term="GZIP"/><category term="HTML5"/><category term="LocalStorage"/><category term="MVC Templates"/><category term="Minification"/><category term="Partial View"/><category term="Performance"/><category term="SPA"/><category term="SessionStorage"/><category term="WebStorage"/><category term="Weekly Update"/><category term="image"/><category term="image album"/><category term="jquery"/><category term="plugin"/><title type='text'>Avi Jassra</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>21</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-3815366307993795020</id><published>2014-05-28T19:53:00.000-04:00</published><updated>2014-05-28T19:53:18.343-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="Project Euler"/><title type='text'>Project Euler - Problem 4 in C#</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;background-color: white; color: #6b4e3d; font-family: Arial, helvetic, sans-serif; margin: 0px; padding: 10px 0px 5px;&quot;&gt;
Largest palindrome product&lt;/h2&gt;
&lt;div class=&quot;info&quot; id=&quot;problem_info&quot; style=&quot;background-color: white; cursor: help; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 14px; position: relative;&quot;&gt;
&lt;h3 style=&quot;color: #666666; font-family: &#39;Courier New&#39;, monospace; margin: 0px;&quot;&gt;
Problem 4&lt;/h3&gt;
&lt;/div&gt;
&lt;div class=&quot;problem_content&quot; role=&quot;problem&quot; style=&quot;background-color: white; border-color: rgb(221, 221, 221) rgb(170, 170, 170) rgb(170, 170, 170) rgb(221, 221, 221); border-style: solid; border-width: 1px; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 16px; padding: 10px;&quot;&gt;
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91&amp;nbsp;&lt;img alt=&quot;×&quot; border=&quot;0&quot; src=&quot;http://projecteuler.net/images/symbol_times.gif&quot; height=&quot;9&quot; style=&quot;border: 0px; vertical-align: middle;&quot; width=&quot;9&quot; /&gt;99.&lt;br /&gt;
Find the largest palindrome made from the product of two 3-digit numbers.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
Sounds like pretty simple problem ... right.&lt;br /&gt;
&lt;br /&gt;
For all the three digit numbers, find the product between them and check if the product of numbers is palindrome or not. And if yes, find the greatest product.&lt;br /&gt;
&lt;br /&gt;
Like explained in the problem, a palindrome is a word, phrase, or number, whose meaning may be interpreted the same way in either forward or reverse direction. To test a palindrome number, we need to reverse the digits of the number. And for that, we iterate using formula ((y*10)&amp;nbsp;+ (x%10)) where y is new reversed number starting from 0 and x is original number to be reversed. Here is the example below to understand it better&lt;br /&gt;
&lt;br /&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; dir=&quot;ltr&quot; style=&quot;border-collapse: collapse; border: 1px solid #ccc; font-family: arial,sans,sans-serif; font-size: 13px; table-layout: fixed;&quot;&gt;&lt;colgroup&gt;&lt;col width=&quot;69&quot;&gt;&lt;/col&gt;&lt;col width=&quot;200&quot;&gt;&lt;/col&gt;&lt;col width=&quot;175&quot;&gt;&lt;/col&gt;&lt;col width=&quot;175&quot;&gt;&lt;/col&gt;&lt;/colgroup&gt;&lt;tbody&gt;
&lt;tr style=&quot;height: 17px;&quot;&gt;&lt;td style=&quot;background-color: #1c4587; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000; border-top: 1px solid #000000; color: white; direction: ltr; font-weight: bold; padding: 0px 3px 0px 3px; text-align: center; vertical-align: bottom;&quot;&gt;Iteration&lt;/td&gt;&lt;td style=&quot;background-color: #1c4587; border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 1px solid #000000; color: white; direction: ltr; font-weight: bold; padding: 0px 3px 0px 3px; text-align: center; vertical-align: bottom;&quot;&gt;Formula &lt;/td&gt;&lt;td style=&quot;background-color: #1c4587; border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 1px solid #000000; color: white; direction: ltr; font-weight: bold; padding: 0px 3px 0px 3px; text-align: center; vertical-align: bottom;&quot;&gt;New Number (y)&lt;/td&gt;&lt;td style=&quot;background-color: #1c4587; border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 1px solid #000000; color: white; direction: ltr; font-weight: bold; padding: 0px 3px 0px 3px; text-align: center; vertical-align: bottom;&quot;&gt;Actual Number (x)&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 17px;&quot;&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;0&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: center; vertical-align: bottom;&quot;&gt;0&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;0&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;98743&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 17px;&quot;&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;1&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(0, 0, 0); border-right-style: solid; border-right-width: 1px; direction: ltr; padding: 0px 3px; text-align: center; vertical-align: bottom;&quot;&gt;(0*10) + (98743%10)&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;3&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;9874&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 17px;&quot;&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;2&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(0, 0, 0); border-right-style: solid; border-right-width: 1px; direction: ltr; padding: 0px 3px; text-align: center; vertical-align: bottom;&quot;&gt;(3*10) + (9874%10)&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;34&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;987&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 17px;&quot;&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;3&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(0, 0, 0); border-right-style: solid; border-right-width: 1px; direction: ltr; padding: 0px 3px; text-align: center; vertical-align: bottom;&quot;&gt;(34*10) + (987%10)&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;347&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;98&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 17px;&quot;&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;4&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(0, 0, 0); border-right-style: solid; border-right-width: 1px; direction: ltr; padding: 0px 3px; text-align: center; vertical-align: bottom;&quot;&gt;(347*10) + (98%10)&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;3478&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;9&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 17px;&quot;&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;5&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(0, 0, 0); border-right-style: solid; border-right-width: 1px; direction: ltr; padding: 0px 3px; text-align: center; vertical-align: bottom;&quot;&gt;(3478*10) + (9%10)&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;34789&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid #000000; border-right: 1px solid #000000; padding: 0px 3px 0px 3px; text-align: right; vertical-align: bottom;&quot;&gt;0&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
Method to reverse digits and test if number is palindrome or not ....&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;// Check is number is palindrome&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt; IsPalindrome(&lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; number)
{
    &lt;span style=&quot;color: green;&quot;&gt;// store the actual number for check&lt;/span&gt;
    &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; actualNumber = number;
    &lt;span style=&quot;color: green;&quot;&gt;// initialize new palindrome number&lt;/span&gt;
    &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; palindromeNumber = 0;

    &lt;span style=&quot;color: green;&quot;&gt;// to reverse the number e.g. 98743 and set new palindrome number to 0&lt;/span&gt;
    &lt;span style=&quot;color: green;&quot;&gt;// multiple new palindrome number with 10, and add modulus when number is divide by 10 and set it back in the new number&lt;/span&gt;
    &lt;span style=&quot;color: green;&quot;&gt;// iteration 1 -&amp;gt; newPalindromeNumber: (0*10 + 98743%10) -&amp;gt; 3; number -&amp;gt; 9874&lt;/span&gt;
    &lt;span style=&quot;color: green;&quot;&gt;// iteration 2 -&amp;gt; newPalindromeNumber: (3*10 + 9874%10) -&amp;gt; 34; number -&amp;gt; 987&lt;/span&gt;
    &lt;span style=&quot;color: green;&quot;&gt;// iteration 3 -&amp;gt; newPalindromeNumber: (34*10 + 987%10) -&amp;gt; 347; number -&amp;gt; 98&lt;/span&gt;
    &lt;span style=&quot;color: green;&quot;&gt;// iteration 4 -&amp;gt; newPalindromeNumber: (347*10 + 98%10) -&amp;gt; 3478; number -&amp;gt; 9&lt;/span&gt;
    &lt;span style=&quot;color: green;&quot;&gt;// iteration 5 -&amp;gt; newPalindromeNumber: (3478*10 + 9%10) -&amp;gt; 34789; number -&amp;gt; 0&lt;/span&gt;
    &lt;span style=&quot;color: green;&quot;&gt;// loops till number is not equal to 0&lt;/span&gt;
    &lt;span style=&quot;color: green;&quot;&gt;// and now we have reversed number to check if its palindrome&lt;/span&gt;
    &lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt; (number != 0)
    {
        palindromeNumber = (palindromeNumber * 10) + (number % 10);
        number = number / 10;
    }
    &lt;span style=&quot;color: green;&quot;&gt;//if actual number and new expected palindrome numbers are same&lt;/span&gt;
    &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; (actualNumber == palindromeNumber);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
Here is the first basic implementation to solve the problem&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;// basic looping&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; IEnumerable&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&amp;gt; ListOfThreeDigitNumbersProduct()
{
    &lt;span style=&quot;color: green;&quot;&gt;// looping for the first 3 digit numbers&lt;/span&gt;
    &lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; i = 999; i &amp;gt; 99; i--)
    {
        &lt;span style=&quot;color: green;&quot;&gt;// looping for the second 3 digit numbers&lt;/span&gt;
        &lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; j = 999; j &amp;gt; 99; j--)
        {
            &lt;span style=&quot;color: green;&quot;&gt;// find the product b/w the numbers&lt;/span&gt;
            &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; product = i*j;

            &lt;span style=&quot;color: green;&quot;&gt;// check if the number is palindome&lt;/span&gt;
            &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (product.IsPalindrome())
            {
                &lt;span style=&quot;color: blue;&quot;&gt;yield&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; product;
            }
        }
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
Whats happening in this solution&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Number x and y iterate from 100 to 999 to find product of x with all the 3 digits y number.&lt;/li&gt;
&lt;li&gt;Every product is verified for palindrome test and if successful, added to the list of palindrome products of 3 digit number&lt;/li&gt;
&lt;li&gt;Max number is picked from the list of palindrome numbers from the list.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; maxProduct = ListOfThreeDigitNumbersProduct().Max();&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Note:&lt;/span&gt;&lt;/b&gt; We don&#39;t need to create the list of palindrome numbers.We can put conditions to always compare and get the largest palindrome number.&lt;br /&gt;
&lt;br /&gt;
This solution works but there is room for improvement .... :) . Here are my observation for improvement for faster solution ...&lt;/div&gt;
&lt;div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Product of x*y is equal to y*x. So we don&#39;t need check the product of x with y and again for x = y and y = x. This can be avoided by setting upper bound y to x.&lt;/li&gt;
&lt;li&gt;If the new product is greater then the previously stored palindrome number, only then we should run palindrome test on the current number. This way we can avoid palindrome test processing time on many numbers, hence making solution faster.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;// intelligent faster solution&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; LargestThreeDigitNumbersProduct()
{
    &lt;span style=&quot;color: green;&quot;&gt;// initialize largest palindrome number variabel&lt;/span&gt;
    &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; largestPalindromeNumber = 0; 

    &lt;span style=&quot;color: green;&quot;&gt;// loopping thru all 3 digit numbers&lt;/span&gt;
    &lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; i = 999; i &amp;gt; 99; i--)
    {
        &lt;span style=&quot;color: green;&quot;&gt;// PERFORMACE BOOST&lt;/span&gt;
        &lt;span style=&quot;color: green;&quot;&gt;// looping thru 3 digits number from 100 to first number&lt;/span&gt;
        &lt;span style=&quot;color: green;&quot;&gt;// anything greater then first number has been already calculated&lt;/span&gt;
        &lt;span style=&quot;color: green;&quot;&gt;// as (a*b) = (b*a)&lt;/span&gt;
        &lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; j = 100; j &amp;lt;= i; j++)
        {
            &lt;span style=&quot;color: green;&quot;&gt;// product of nunmbers&lt;/span&gt;
            &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; product = i*j;

            &lt;span style=&quot;color: green;&quot;&gt;// PERFORMACE BOOST&lt;/span&gt;
            &lt;span style=&quot;color: green;&quot;&gt;// if current product is greated then the previous saved palindrome product&lt;/span&gt;
            &lt;span style=&quot;color: green;&quot;&gt;// only then check for number is palindrome else we can avoid extra checking task&lt;/span&gt;
            &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (product &amp;gt; largestPalindromeNumber) 
            {
                &lt;span style=&quot;color: green;&quot;&gt;// check number is palindrome&lt;/span&gt;
                &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (product.IsPalindrome())
                {
                    &lt;span style=&quot;color: green;&quot;&gt;// if is palindrome, save it as largest palindrome number &lt;/span&gt;
                    largestPalindromeNumber = product;
                }
            }
        }
    }

    &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; largestPalindromeNumber;
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Link to &lt;a href=&quot;http://avijassra.blogspot.com/2014/05/project-euler-problem-3-in-c.html&quot;&gt;Problem #3&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
If you have a better solution, please don&#39;t hide it from us .... share your knowledge ... :) .... till then, enjoy solving problems.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/3815366307993795020/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2014/05/project-euler-problem-4-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/3815366307993795020'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/3815366307993795020'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2014/05/project-euler-problem-4-in-c.html' title='Project Euler - Problem 4 in C#'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-967921477807778294</id><published>2014-05-27T07:42:00.000-04:00</published><updated>2014-05-28T19:54:23.157-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="Project Euler"/><title type='text'>Project Euler - Problem 3 in C#</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;background-color: white; color: #6b4e3d; font-family: Arial, helvetic, sans-serif; margin: 0px; padding: 10px 0px 5px;&quot;&gt;
Largest prime factor&lt;/h2&gt;
&lt;div class=&quot;info&quot; id=&quot;problem_info&quot; style=&quot;background-color: white; cursor: help; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 14px; position: relative;&quot;&gt;
&lt;h3 style=&quot;color: #666666; font-family: &#39;Courier New&#39;, monospace; margin: 0px;&quot;&gt;
Problem 3&lt;/h3&gt;
&lt;/div&gt;
&lt;div class=&quot;problem_content&quot; role=&quot;problem&quot; style=&quot;background-color: white; border-color: rgb(221, 221, 221) rgb(170, 170, 170) rgb(170, 170, 170) rgb(221, 221, 221); border-style: solid; border-width: 1px; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 16px; padding: 10px;&quot;&gt;
The prime factors of 13195 are 5, 7, 13 and 29.&lt;br /&gt;
What is the largest prime factor of the number 600851475143 ?&lt;/div&gt;
&lt;br /&gt;
To find the largest prime factor of a number x, we can do it in couple of ways. One way is the start dividing the number x by y = 2, 3, 4 ... For each factor y of x, this will remove all the smaller factors before moving to the next y till y is less then x. This will work but there is room for improvement over here.&lt;br /&gt;
&lt;br /&gt;
Let improve this existing solution with some facts.&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;2 is the only even prime number, so we can eliminate all the even numbers by recursively dividing the number by 2. Then we can find the prime factor of new whole number faster by incrementing divisor by 2 starting from 3.&lt;/li&gt;
&lt;li&gt;If we don&#39;t find the prime factor of x until y (number we are testing to be prime factorial starting from 3) is less then equal to square root of x, means we have a tested all the possible options and no more factors are present.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Here is the function to find the largest prime factor of a given number.&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;long&lt;/span&gt; LargestPrimeFactorByDividingBy2InLoopsInitially(&lt;span style=&quot;color: blue;&quot;&gt;long&lt;/span&gt; number)
{
    &lt;span style=&quot;color: green;&quot;&gt;// set the initial dividing number&lt;/span&gt;
    &lt;span style=&quot;color: blue;&quot;&gt;long&lt;/span&gt; dividingNumber = 2;
    &lt;span style=&quot;color: green;&quot;&gt;// looping to divide with only even prime number to remove all possible even numbers&lt;/span&gt;
    &lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt; (number % 2 == 0)
    {
        number = number / 2;
    }
    &lt;span style=&quot;color: green;&quot;&gt;// no even number is left, hence starting with 3&lt;/span&gt;
    dividingNumber = 3;
    &lt;span style=&quot;color: green;&quot;&gt;// divide in loops until dividing number is less then square root of expected lpf&lt;/span&gt;
    &lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt; (System.Math.Sqrt(number) &amp;gt; dividingNumber)
    {
        &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (number % dividingNumber == 0)
        {
            &lt;span style=&quot;color: green;&quot;&gt;// if expected lpf is divisible, update the number&lt;/span&gt;
            number = number / dividingNumber;
        }
        &lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;
        {
            dividingNumber += 2;
        }
    }

    &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; number;
}&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
Link to &lt;a href=&quot;http://avijassra.blogspot.com/2014/05/project-euler-problem-2-in-c.html&quot;&gt;Problem #2&lt;/a&gt;&lt;br /&gt;
Link to &lt;a href=&quot;http://avijassra.blogspot.com/2014/05/project-euler-problem-4-in-c.html&quot;&gt;Problem #4&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
If you have any better and faster way, please share it with us. Till then, enjoy solving problems .....&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/967921477807778294/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2014/05/project-euler-problem-3-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/967921477807778294'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/967921477807778294'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2014/05/project-euler-problem-3-in-c.html' title='Project Euler - Problem 3 in C#'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-6185159698687849029</id><published>2014-05-25T21:48:00.001-04:00</published><updated>2014-05-25T21:48:44.681-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Experience"/><category scheme="http://www.blogger.com/atom/ns#" term="Weekly Update"/><title type='text'>Word of Experience</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
While working in the corporate sector, we face different set challenges everyday. They might not always related to our work but sometimes with our attitude towards our work (which might be intentionally or unintentionally).&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;DISCLAIMER:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
I am very firm believer of doing things as if i won&#39;t do it, someone else will.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Experience:&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Being too much technical is also problem sometimes. You start understanding all the business requirements/problems more by technical implementation (virtually creating solution in head at the very same instance) rather then understanding it as something user will like to have in a product which helps them to complete the task.&lt;br /&gt;
Recently we created a small app in my current engagement. It was almost complete (with couple of defects ... :) ). While trying to understand a defect, my manager came up with all together new requirement which potentially changes the complete or major portion of the JavaScript architecture. We developers (my colleague and myself) resisted back for that change in front of higher management. It was big change, potentially forcing us to go back to drawing board and redesign the whole thing again.&lt;br /&gt;
&lt;br /&gt;
My intentions were good because we have completed our application and more over it was never part of the requirements. I was not afraid of the change but somehow resisted because timeline does not look good with release date.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
And soon it was time to have a word with my friend (who happens to be my manager too). He made me realize that changes are inevitable in the cycle of software development (which i knew) and may be what i was saying was right too, bring such big changes in the last minute was not a good idea too. But i was not conveying my message properly. All management could see was me trying to push back on the work and truly, that was not my intention. What i should have done was, tell them how big impact this is on the current architecture and time line required to revisit the design for new requirement. I will come out as a winner with positive attitude towards my work and also lay it down in front of management. And its their call to go ahead with change accepting new timeline, play gamble to push new changes in current timeline or put it in phase 2 of the application.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Lesson:&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;-webkit-text-stroke-width: 0px; color: black; font-family: &#39;Times New Roman&#39;; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
Its very important to understand our audience and talk in there language. Management does not care about technical issues we face while development. If business needs something, it needs it .... that&#39;s it. But what they care about is budget and are we on time for release or not. Its more important for we developers to play along and be flexible with new requirements. Always high light issues in positive attitude towards work, try to talk to management in their language, i.e. budget, time to finish task and let them take decision.&lt;br /&gt;
&lt;br /&gt;
I know many of you guys already do this but this was high light of my week. And hope this helps some developer out there too ...&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/6185159698687849029/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2014/05/word-of-experience.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/6185159698687849029'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/6185159698687849029'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2014/05/word-of-experience.html' title='Word of Experience'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-5665242894493282327</id><published>2014-05-15T19:45:00.000-04:00</published><updated>2014-05-15T19:45:43.955-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="C# 6.0"/><title type='text'>Expected in C# 6.0</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Mads Torgersen (Program Manager for Managed Languages) from the C# design team covered some of the new probable features in C# 6.0 in Build 2014 (&lt;a href=&quot;http://channel9.msdn.com/Events/Build/2014/2-577&quot;&gt;Click here&lt;/a&gt; to view the video).&lt;br /&gt;
&lt;br /&gt;
Lets drill down some of the highlighted features&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Auto-Properties w/ Initializer:&lt;/h3&gt;
Initializing a immutable class is a tedious process currently&lt;br /&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;Before&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; _x;
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; X { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt; { &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; _x; } }

&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; Y { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;; }
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;With C# 6.0&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; X { &lt;span style=&quot;color: blue;&quot;&gt;get;&lt;/span&gt; } = _x;

&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; Y { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;; } = _y;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;Thoughts&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
Instead of creating private members to set the value and return in getter or use private setter. We can initialize the property like this. Very useful for the immutable classes.&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Primary Constructor:&lt;/h3&gt;
Shorter and cleaner way to write constructor where we are just setting the values to the properties with private set without any extra validation. &lt;br /&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;Before&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; Person
{
    &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; _name;

    &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; Person(&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; name, &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; age)
    {
        _name = name;
        Age = age;
    }

    &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; Name { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt; { &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; _name; } }

    &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; Age { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;; }&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;    &lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;    &lt;/span&gt;.....
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;With C# 6.0&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; Person(&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; name, &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; age)
{
    &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; Name { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;; } = name;

    &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; Age { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;; } = age;

    .....
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;Thoughts&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
Combination of auto properties initializer and primary constructor will simplify C# code a lot.&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Static using statement:&lt;/h3&gt;
Now in C#6.0, we can include static classes in the scope.&lt;br /&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;Before&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System;
......
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;double&lt;/span&gt; Distance { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt; { &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; Math.Sqrt(16); } }&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;With C# 6.0&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System.Math;
......
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;double&lt;/span&gt; Distance { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt; { &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; Sqrt(16); } }&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;Thoughts&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
Nice to have feature. It can help in reducing lot of key strokes of including static class name again and again.&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Property/Method Expression:&lt;/h3&gt;
&lt;div&gt;
Property and method syntax simplified for short hand. Looks more like LINQ statement but has nothing to do with it.&lt;/div&gt;
&lt;div&gt;
&lt;i&gt;&lt;br class=&quot;Apple-interchange-newline&quot; /&gt;&lt;/i&gt; &lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;Before&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
&lt;div style=&quot;background-color: #f0f0f0; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em !important; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 16.25px;&quot;&gt;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;double&lt;/span&gt; Distance { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt; { &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; Math.Sqrt(16); } }

&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; Point Move(&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; dx, &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; dy) 
{
    &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Point(x + dx, y + dy);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;With C# 6.0&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
&lt;div style=&quot;background-color: #f0f0f0; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em !important; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 16.25px;&quot;&gt;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;// Property expression&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 10pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 10pt;&quot;&gt;double&lt;/span&gt;&lt;span style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 10pt;&quot;&gt; Distance =&amp;gt; Math.Sqrt(16);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 16.25px;&quot;&gt;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;
&lt;span style=&quot;color: green;&quot;&gt;// Method expression&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; Point Move(&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; dx, &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; dy) =&amp;gt; &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Point(x + dx, y + dy);&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;Thoughts&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
Nice to have feature.&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Declaration Expression:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Instead of limiting variables to declaration statement, going forward we can declare them in the middle of the expression where they are need&lt;br /&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;Before&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
&lt;div style=&quot;background-color: #f0f0f0; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em !important; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 16.25px;&quot;&gt;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; val;

&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; isValid = &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;.TryParse (&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;1231&quot;&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;out&lt;/span&gt; val);&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;With C# 6.0&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
&lt;div style=&quot;background-color: #f0f0f0; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em !important; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 16.25px;&quot;&gt;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; isValid = &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;.TryParse (&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;1231&quot;&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;out&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; val);&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;Thoughts&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
Nice to have feature.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Params for Enumerable:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Now will be able to send params of enumerables instead of limiting to arrays.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;Before&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
&lt;div style=&quot;background-color: #f0f0f0; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em !important; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 16.25px;&quot;&gt;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; SomeMethod(&lt;span style=&quot;color: blue;&quot;&gt;params&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;[] vals) 
{
    .....
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;With C# 6.0&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
&lt;div style=&quot;background-color: #f0f0f0; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em !important; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 16.25px;&quot;&gt;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; SomeMethod(&lt;span style=&quot;color: blue;&quot;&gt;params&lt;/span&gt; IEnumerable&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&amp;gt; vals) 
{
    .....
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;Thoughts&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
Again, nice to have feature. Will not have to convert enumerables into array anymore for the params.&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Monadic null check:&lt;/h3&gt;
&lt;div&gt;
Removes the need to check for nulls before accessing properties or methods. Known as the &lt;a href=&quot;http://groovy.codehaus.org/Operators#Operators-SafeNavigationOperator(?.&quot;&gt;Safe Navigation Operator&lt;/a&gt; in Groovy).&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;Before&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
&lt;div style=&quot;background-color: #f0f0f0; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em !important; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 16.25px;&quot;&gt;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (points != &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;) {
    &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; next = points.FirstOrDefault();
    &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (next != &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp; next.X != &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;) &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; next.X;
}   
&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; -1;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;With C# 6.0&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
&lt;div style=&quot;background-color: #f0f0f0; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em !important; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 16.25px;&quot;&gt;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; bestValue = points?.FirstOrDefault()?.X ?? -1;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;Thoughts&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
Awesome. Will reduce lot of noise in the code.&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Await Calls from Within a Catch Block:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;With C# 6.0&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
&lt;div style=&quot;background-color: #f0f0f0; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em !important; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 16.25px;&quot;&gt;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 10pt; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt;
{
    WebRequest webRequest =
        WebRequest.Create(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;http://IntelliTect.com&quot;&lt;/span&gt;);
    WebResponse response =
        &lt;span style=&quot;color: blue;&quot;&gt;await&lt;/span&gt; webRequest.GetResponseAsync();
    &lt;span style=&quot;color: green;&quot;&gt;// ...&lt;/span&gt;
}
&lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (WebException exception)
{
    &lt;span style=&quot;color: blue;&quot;&gt;await&lt;/span&gt; WriteErrorToLog(exception);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;&lt;u&gt;Thoughts&lt;/u&gt;&lt;/i&gt;&lt;/h4&gt;
Have not used a lot. No Comments.&lt;br /&gt;
&lt;br /&gt;
All these features look pretty interesting. Looking forward to C# 6.0&lt;br /&gt;
&lt;br /&gt;
Happy Coding ...&lt;/div&gt;
&lt;div&gt;
&lt;strong style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Segoe UI&#39;, &#39;Lucida Grande&#39;, Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16.001602172851563px; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;&lt;br /&gt;
&lt;/strong&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/5665242894493282327/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2014/05/expected-in-c-60.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/5665242894493282327'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/5665242894493282327'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2014/05/expected-in-c-60.html' title='Expected in C# 6.0'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-3264968260246465767</id><published>2014-05-12T21:38:00.000-04:00</published><updated>2014-05-27T07:44:09.549-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="Project Euler"/><title type='text'>Project Euler - Problem 2 in C#</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;background-color: white; color: #6b4e3d; font-family: Arial, helvetic, sans-serif; margin: 0px; padding: 10px 0px 5px;&quot;&gt;
Even Fibonacci numbers&lt;/h2&gt;
&lt;div class=&quot;info&quot; id=&quot;problem_info&quot; style=&quot;background-color: white; cursor: help; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 14px; position: relative;&quot;&gt;
&lt;h3 style=&quot;color: #666666; font-family: &#39;Courier New&#39;, monospace; margin: 0px;&quot;&gt;
Problem 2&lt;/h3&gt;
&lt;/div&gt;
&lt;div class=&quot;problem_content&quot; role=&quot;problem&quot; style=&quot;background-color: white; border-color: rgb(221, 221, 221) rgb(170, 170, 170) rgb(170, 170, 170) rgb(221, 221, 221); border-style: solid; border-width: 1px; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 16px; padding: 10px;&quot;&gt;
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...&lt;/div&gt;
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.&lt;/div&gt;
&lt;br /&gt;
We have two options to solve this problem, declarative or imperative approach. Declarative approach has two steps&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;i&gt;&lt;u&gt;Step 1:&lt;/u&gt;&lt;/i&gt; Generate the list of all the numbers in fibonacci series less then equal to 4 million&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;static&lt;/span&gt; IEnumerable&amp;lt;&lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt;&amp;gt; GenerateList(&lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt; upperBound)
{
&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; (upperBound &amp;lt; &lt;span style=&quot;color: #40a070;&quot;&gt;2&lt;/span&gt;)
&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;{
&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;&lt;/code&gt; &lt;span style=&quot;color: #007020; font-weight: bold; line-height: 125%;&quot;&gt;throw&lt;/span&gt;&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #007020; font-weight: bold; line-height: 125%;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #06287e; line-height: 125%;&quot;&gt;Exception&lt;/span&gt;&lt;span style=&quot;line-height: 125%;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #4070a0; line-height: 125%;&quot;&gt;&quot;Invalid upper bound&quot;&lt;/span&gt;&lt;span style=&quot;line-height: 125%;&quot;&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; }

&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;IList&amp;lt;&lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt;&amp;gt; list = &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;new&lt;/span&gt; List&amp;lt;&lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt;&amp;gt;();

&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; prev1 = &lt;span style=&quot;color: #40a070;&quot;&gt;1&lt;/span&gt;;
&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;list.Add(prev1);
&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; prev2 = &lt;span style=&quot;color: #40a070;&quot;&gt;2&lt;/span&gt;;
&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;list.Add(prev2);
&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; sum = &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;;

&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;while&lt;/span&gt; (sum &amp;lt; upperBound)
&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;{
&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;&lt;/code&gt; &lt;span style=&quot;line-height: 125%;&quot;&gt;sum = prev1 + prev2;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; &lt;/code&gt; &lt;span style=&quot;line-height: 125%;&quot;&gt;list.Add(sum);&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;                prev1 = prev2;
                prev2 = sum;
&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;}

&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;return&lt;/span&gt; list;
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;font-style: italic; text-align: left; text-decoration: underline;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;i style=&quot;font-style: italic; text-decoration: underline;&quot;&gt;&lt;u&gt;Step 2:&lt;/u&gt;&lt;/i&gt; Sum all the even numbers in the list&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;/ul&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// OPTION 1&lt;/span&gt;
&lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; sum = GenerateList(&lt;span style=&quot;color: #40a070;&quot;&gt;4000000&lt;/span&gt;)
&lt;span style=&quot;line-height: 125%;&quot;&gt; &lt;/span&gt;&lt;/code&gt; &lt;span style=&quot;line-height: 125%;&quot;&gt;.Where(x =&amp;gt; x % &lt;/span&gt;&lt;span style=&quot;color: #40a070; line-height: 125%;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;line-height: 125%;&quot;&gt; == &lt;/span&gt;&lt;span style=&quot;color: #40a070; line-height: 125%;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;line-height: 125%;&quot;&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; &lt;/code&gt; &lt;span style=&quot;line-height: 125%;&quot;&gt;.Sum();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;
&lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// By creating list first and reducing list to +ve numbers and finding their sum&lt;/span&gt;
Console.WriteLine(sum);&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;
In the imperative approach, sum the even number while generating the fibonacci series in the loop itself.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// OPTION 2&lt;/span&gt;
&lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; prev1 = &lt;span style=&quot;color: #40a070;&quot;&gt;1&lt;/span&gt;;
&lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; prev2 = &lt;span style=&quot;color: #40a070;&quot;&gt;2&lt;/span&gt;;&lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// prev2 value is 2 which is a even number, so sum starts from 2&lt;/span&gt;
&lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; sumByLooping = prev2;

&lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;while&lt;/span&gt;(prev2 &amp;lt;= &lt;span style=&quot;color: #40a070;&quot;&gt;4000000&lt;/span&gt;)&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;{
 &lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; sumOf2Nos = prev1 + prev2;

 prev1 = prev2;
 prev2 = sumOf2Nos;

 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; (sumOf2Nos % &lt;span style=&quot;color: #40a070;&quot;&gt;2&lt;/span&gt; == &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; {
  sumByLooping += sumOf2Nos;
 }
}

&lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// By looping thru numbers and adding only +ve numbers&lt;/span&gt;
Console.WriteLine(sumByLooping);
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Link to&amp;nbsp;&lt;a href=&quot;http://avijassra.blogspot.com/2014/05/project-euler-problem-1-in-c.html&quot;&gt;Problem #1&lt;/a&gt;&lt;br /&gt;
Link to &lt;a href=&quot;http://avijassra.blogspot.com/2014/05/project-euler-problem-3-in-c.html&quot;&gt;Problem #3&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Have fun solving problems ....&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/3264968260246465767/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2014/05/project-euler-problem-2-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/3264968260246465767'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/3264968260246465767'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2014/05/project-euler-problem-2-in-c.html' title='Project Euler - Problem 2 in C#'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-7508344859713181071</id><published>2014-05-10T23:00:00.000-04:00</published><updated>2014-05-10T23:00:26.355-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="Dependency Injection"/><category scheme="http://www.blogger.com/atom/ns#" term="DI"/><title type='text'>What is Dependency Injection? And why it is so important?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;i style=&quot;color: black; font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;&quot;&gt;&lt;b&gt;Definition found on WIKI&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;Dependency injection is a software design pattern that implements&lt;/span&gt;&lt;a href=&quot;http://en.m.wikipedia.org/wiki/Inversion_of_control&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: #1155cc; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; inversion of control&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; and allows a program design to follow the&lt;/span&gt;&lt;a href=&quot;http://en.m.wikipedia.org/wiki/Dependency_inversion_principle&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: #1155cc; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; dependency inversion principle&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;. The term was coined by&lt;/span&gt;&lt;a href=&quot;http://en.m.wikipedia.org/wiki/Martin_Fowler&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: #1155cc; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; Martin Fowler&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;An injection is the passing of a dependency (a service) to a dependent object (a client). The service is made part of the client&#39;s state. Passing the service to the client, rather than allowing a client to build or find the service, is the fundamental requirement of the pattern.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15;&quot;&gt;
&lt;b style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;
&lt;/b&gt; &lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;color: black; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;span style=&quot;font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt;&lt;i&gt;&lt;u&gt;Means:&lt;/u&gt;&lt;/i&gt;&lt;b&gt; &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;&quot;&gt;The dependency should be injected to a object which it needs to complete their unit of work. If object A needs object B to complete its unit of work, then B should be provided to A instead of A creating object B. This also means abstraction should not depend on details but instead details should depend on abstractions.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15;&quot;&gt;
&lt;b style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;Let&#39;s drill down into this and try to make more sense out of this with examples.&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: red; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;b&gt;NOTE:&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; All my examples will be using C# language&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;Lets assume, in my application i need to send updates&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt;like email &lt;/span&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;&quot;&gt;to user when a particular task is complete. So based on the requirement, i wrote a class which sends email messages to the users.&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;EmailNotifier&lt;/span&gt;
{
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #06287e;&quot;&gt;Send&lt;/span&gt;(&lt;span style=&quot;color: #902000;&quot;&gt;string&lt;/span&gt; message)
  {
   &lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// code to send email to the user&lt;/span&gt;
  }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;span id=&quot;docs-internal-guid-daf649ca-d410-7f67-e1f7-eb8e86e1ce89&quot;&gt;&lt;span style=&quot;color: black; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;So in my code, i will be using email notifier to send email messages on complete of a task to respective users.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;Task&lt;/span&gt; 
{
  &lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// other methods for the task class&lt;/span&gt;

  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #06287e;&quot;&gt;OnComplete&lt;/span&gt;(&lt;span style=&quot;color: #902000;&quot;&gt;string&lt;/span&gt; message)
  {
   &lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// notify user with message&lt;/span&gt;
   &lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; notifier = &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;new&lt;/span&gt; EmailNotifier();
   notifier.Send(message);
  }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;color: black; line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;Now this is all good but we have couple of concerns over here.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;b&gt;&lt;i&gt;Issue:&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: black; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt;Testing&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;Since my code has dependency on the external class, we have to make sure that its dependencies are always available, up and running for testing. Plus we cannot do unit testing of our unit of work as we will be testing notifier class and its dependencies too.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;b&gt;&lt;i&gt;Solution:&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;Instead of creating the instance of the notifier class inside task object, we can pass the object as an parameter in the class. This is also known as &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt;Dependency Injection&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;. Doing so, our code will not require to know how to build notifier object, and for testing we can pass the mocked object(s) which simulates different behavior to capture different scenarios.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;Task&lt;/span&gt; 
 {
  EmailNotifier _emailNotifier;

  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #06287e;&quot;&gt;Task&lt;/span&gt;(EmailNotifier emailNotifier)
  {
   _emailNotifier = emailNotifier;
  }

  &lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// other methods for the task class&lt;/span&gt;

  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #06287e;&quot;&gt;OnComplete&lt;/span&gt;(&lt;span style=&quot;color: #902000;&quot;&gt;string&lt;/span&gt; message)
  {
   &lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// notify user with message&lt;/span&gt;
   _emailNotifier.Send(message);
  }
 }&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;color: black; line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;With this solution, task class gets the notifier object injected as parameter. Task class is no longer responsible for creating the notifier object.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;This is good but it can be still improved by making this &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt;loosely coupled&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;. What exactly this means? To understand this, first we need to understand tight coupling.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;b&gt;&lt;i&gt;Tight Coupling:&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;In computer science, &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt;tight coupling&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; (or &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt;tightly coupled&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;) is a type of coupling that describes a system in which hardware and software are not only linked together, but are also dependent upon each other. One of the common characteristics of tight coupling are&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;ul style=&quot;line-height: 1.15; text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;color: black; font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;&quot;&gt;A change in one module usually forces a ripple effect of changes in other modules.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: black; font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;&quot;&gt;Assembly of modules might require more effort and/or time due to the increased inter-module dependency.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: black; font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;&quot;&gt;A particular module might be harder to reuse and/or test because dependent modules must be included.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;b&gt;&lt;i&gt;Loose Coupling:&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;div style=&quot;line-height: 1.15;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;In computing and systems design, a&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt; loosely coupled&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; system is one in which each of its components has, or makes use of, little or no knowledge of the definitions of other separate components.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 1.15;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt;In the above code, even though we are injecting dependencies, still it is tightly coupled because it directly depends on concrete object. Any new requirement will cause ripple effect of changes e.g. if business comes up with new requirement of sending user notification via SMS, twitter, etc. To accommodate the new requirement, we can either change the base class to implement new notifications but that change will effect the way updates are sent where ever its being used for this service, which might not be the requirement. In another solution, we can inject all of the notification objects (like email, SMS etc) in the task class. Problem with this approach is that we will be creating instance of all notifiers even though we will be using few of them depending on requirement,&amp;nbsp;we will &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt;clutter our code with if else statements&lt;/span&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt; and this is memory heavy too. It will work but again, its not the most desirable way of implementing a solution. Anytime new mode of notification is required, we have to change our code, including business logic.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;span style=&quot;color: black; font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;span style=&quot;color: black; font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt;Better solution would be to pass an abstraction/interface as a dependency. We can create a interface which describe how a Notifier class should look like. Then we will implement different ways of notifiers against this contract like this&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;interface&lt;/span&gt; INotifier
 {
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #06287e;&quot;&gt;Send&lt;/span&gt;(&lt;span style=&quot;color: #902000;&quot;&gt;string&lt;/span&gt; message);
 }

 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;EmailNotifier&lt;/span&gt; : INotifier
 {
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #06287e;&quot;&gt;Send&lt;/span&gt;(&lt;span style=&quot;color: #902000;&quot;&gt;string&lt;/span&gt; message)
  {
   &lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// code to send email to the user&lt;/span&gt;
  }
 }

 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;SmsNotifier&lt;/span&gt; : INotifier
 {
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #06287e;&quot;&gt;Send&lt;/span&gt;(&lt;span style=&quot;color: #902000;&quot;&gt;string&lt;/span&gt; message)
  {
   &lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// code to send sms to the user&lt;/span&gt;
  }
 }

 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;EmailAndSmsNotifier&lt;/span&gt; : INotifier
 {
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #06287e;&quot;&gt;Send&lt;/span&gt;(&lt;span style=&quot;color: #902000;&quot;&gt;string&lt;/span&gt; message)
  {
   &lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// code to send email and sms to the user&lt;/span&gt;
  }
 }
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;&lt;span style=&quot;font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt;Now, instead of injecting concrete class, we can inject interface as dependency which promises methods or properties to be present in any class which implements it. This is how new task class will look like&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;Task&lt;/span&gt; 
 {
  INotifier _notifier;

  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #06287e;&quot;&gt;Task&lt;/span&gt;(INotifier notifier)
  {
   _notifier = notifier;
  }

  &lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// other methods for the task class&lt;/span&gt;

  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #06287e;&quot;&gt;OnComplete&lt;/span&gt;(&lt;span style=&quot;color: #902000;&quot;&gt;string&lt;/span&gt; message)
  {
   &lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// notify user with message&lt;/span&gt;
   _notifier.Send(message);
  }
 }
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: Arial; font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt;With new changes we can inject the different types of notifiers user want. In future, any new business need of notifications can been implemented without any major change in the code. We will need to create new class implementing the interface, test it as unit of work and inject it as dependency.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: Arial; font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt;
&lt;/span&gt; &lt;span style=&quot;color: black; font-family: Arial; font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt;Now the bigger question is, how we inject these dependencies ... &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: Arial; font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt;
&lt;/span&gt; &lt;span style=&quot;color: black; font-family: Arial; font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt;One way is to create factory classes for resolving out dependencies but in any scenario, we will clutter our code with tight coupling.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: Arial; font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt;Other solution is to use DI APIs. They are handy in registering and resolving interface/class types. Registration can been done at the application start. We can update the framework to use our DI object to resolve types in code.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: Arial; font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: Arial; font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt;Stayed tuned to my next article to learn more about how to use Unity, DI API in .net applications.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;span style=&quot;font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;span style=&quot;font-size: 15px; line-height: 17.25px; white-space: pre-wrap;&quot;&gt;Till then, Happy coding ...&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/7508344859713181071/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2014/05/what-is-dependency-injection-and-why-it.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/7508344859713181071'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/7508344859713181071'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2014/05/what-is-dependency-injection-and-why-it.html' title='What is Dependency Injection? And why it is so important?'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-4700644635761354167</id><published>2014-05-10T22:02:00.000-04:00</published><updated>2014-05-12T21:42:00.332-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="Project Euler"/><title type='text'>Project Euler - Problem 1 in C#</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;background-color: white; color: #6b4e3d; font-family: Arial, helvetic, sans-serif; margin: 0px; padding: 10px 0px 5px;&quot;&gt;
Multiples of 3 and 5&lt;/h2&gt;
&lt;div class=&quot;info&quot; style=&quot;background-color: white; cursor: help; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 14px; margin-bottom: 10px; position: relative; width: 200px;&quot;&gt;
&lt;h3 style=&quot;color: #666666; font-family: &#39;Courier New&#39;, monospace; margin: 0px;&quot;&gt;
Problem 1&lt;/h3&gt;
&lt;/div&gt;
&lt;div class=&quot;problem_content&quot; role=&quot;problem&quot; style=&quot;background-color: white; border-color: rgb(221, 221, 221) rgb(170, 170, 170) rgb(170, 170, 170) rgb(221, 221, 221); border-style: solid; border-width: 1px; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 16px; padding: 10px;&quot;&gt;
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.&lt;br /&gt;
Find the sum of all the multiples of 3 or 5 below 1000.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Here is my solution&lt;br /&gt;
&lt;br /&gt;
For this problem, either we can create list of int or array of int values up to 1000 like this&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// generate the list of numbers from lower bound to upper down&lt;/span&gt;
&lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;static&lt;/span&gt; IList&amp;lt;&lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt;&amp;gt; GenerateNumberList(&lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt; upperBound, &lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt; lowerBound = &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;)
{
 &lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; numberList = &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;new&lt;/span&gt; List&amp;lt;&lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt;&amp;gt;();

 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; i = lowerBound; i &amp;lt; upperBound; i++)
 {
  numberList.Add(i);
 }

 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;return&lt;/span&gt; numberList;
}

&lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// generate the array of numbers from lower bound to upper down&lt;/span&gt;
&lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #06287e;&quot;&gt;GenerateNumberArray&lt;/span&gt;(&lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt; upperBound, &lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt; lowerBound = &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;)
{
 &lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; arrLength = upperBound - lowerBound;

 &lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; numberArr = &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt;[arrLength];

 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; i = &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;; i &amp;lt; arrLength; i++)
 {
  numberArr[i] = lowerBound + i;
 }

 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;return&lt;/span&gt; numberArr;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
Using LINQ for the declarative approach to find the sum of all the numbers either divisible by 3 or 5&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0; width: 100% !important;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// OPTION 1&lt;/span&gt;
stopwatch.Start();

&lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; listSum = GenerateNumberList(&lt;span style=&quot;color: #40a070;&quot;&gt;1000&lt;/span&gt;)
   .Where(x =&amp;gt; x % &lt;span style=&quot;color: #40a070;&quot;&gt;3&lt;/span&gt; == &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt; || x % &lt;span style=&quot;color: #40a070;&quot;&gt;5&lt;/span&gt; == &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;)
   .Sum();

stopwatch.Stop();

&lt;span style=&quot;line-height: 125%;&quot;&gt;Console.WriteLine&lt;/span&gt; (listSum);

&lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// OPTION 2&lt;/span&gt;
stopwatch.Reset ();
stopwatch.Start ();

&lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; arrSum = GenerateNumberArray (&lt;span style=&quot;color: #40a070;&quot;&gt;1000&lt;/span&gt;)
   .Where (x =&amp;gt; x % &lt;span style=&quot;color: #40a070;&quot;&gt;3&lt;/span&gt; == &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt; || x % &lt;span style=&quot;color: #40a070;&quot;&gt;5&lt;/span&gt; == &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;)
   .Sum ();

stopwatch.Stop();

&lt;span style=&quot;line-height: 125%;&quot;&gt;Console.WriteLine&lt;/span&gt; (arrSum);
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0; width: 100% !important;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
With imperative way of programming without using LINQ, we can run the for loop from 0 to 1000 and keep adding all number which meet the criteria.&lt;br /&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em !important; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0; width: 100% !important;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// OPTION 3&lt;/span&gt;
stopwatch.Reset ();
stopwatch.Start ();

&lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; sum = &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;;

&lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;for&lt;/span&gt;(&lt;span style=&quot;color: #902000;&quot;&gt;var&lt;/span&gt; i = &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;; i &amp;lt; &lt;span style=&quot;color: #40a070;&quot;&gt;1000000&lt;/span&gt;; i++) {
 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; (i % &lt;span style=&quot;color: #40a070;&quot;&gt;3&lt;/span&gt; == &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt; || i % &lt;span style=&quot;color: #40a070;&quot;&gt;5&lt;/span&gt; == &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;) {
  sum += i;
 }
}

stopwatch.Stop ();

Console.WriteLine (sum);&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0; width: 100% !important;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;a href=&quot;http://avijassra.blogspot.com/2014/05/project-euler-problem-2-in-c.html&quot;&gt;Click here&lt;/a&gt; to next problem&lt;br /&gt;
&lt;br /&gt;
Have fun solving problems ...&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/4700644635761354167/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2014/05/project-euler-problem-1-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/4700644635761354167'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/4700644635761354167'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2014/05/project-euler-problem-1-in-c.html' title='Project Euler - Problem 1 in C#'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-1916283121305925231</id><published>2014-05-04T13:04:00.002-04:00</published><updated>2014-05-04T13:04:26.001-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AngularJS"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="SPA"/><title type='text'>What is AngularJS? ... And why AngularJS?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b&gt;What is AngularJS?&lt;/b&gt;&lt;br /&gt;
AngularJS is a modern JavaScript framework to build &lt;a href=&quot;http://en.wikipedia.org/wiki/Single-page_application&quot; target=&quot;_blank&quot;&gt;SPA&lt;/a&gt; (Single-Page Applications). It is a hybrid of &lt;a href=&quot;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&quot; target=&quot;_blank&quot;&gt;MVC&lt;/a&gt; (Model-View-Controller) and &lt;a href=&quot;http://en.wikipedia.org/wiki/Model_View_ViewModel&quot; target=&quot;_blank&quot;&gt;MVVM&lt;/a&gt; (Model View ViewModel) architecture. They (AngularJS team) sometimes proudly call themselves as MV* (Model View Whatever) framework. Before we go in depth about Angular, lets understand what is SPA?&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What is SPA&lt;/b&gt;?&lt;br /&gt;
Single Page Application (aka SPA) is taking the web application world by the storm. The goal of the SPA is to provide user with a very responsive and user friendly UI interface. &amp;nbsp;These applications uses web page as a shell and content of the page is refreshed completely or partially without causing complete reload of the page. The three building blocks of the SPA are HTML, CSS and JavaScript on the client side and any server language of desire.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Challenges of creating SPA?&lt;/b&gt;&lt;br /&gt;
In SPA applications, updating the content of the page through&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Ajax_(programming)&quot; target=&quot;_blank&quot;&gt;AJAX&lt;/a&gt; calls and not reloading complete page causes its own issues. Here are the some of the issues&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;u&gt;JavaScript Heavy application:&lt;/u&gt;&amp;nbsp;SPA application uses lot of JavaScript to manipulate HTML DOM on the client side. Normally all SPA are heavy client side applications. This means, writing lot of JavaScript. With the traditional way of writing JavaScript code, we (and not all of us) normally bind everything to the global namespace when we declare variables which can result lot of conflicts and hard to manage code as it is not modularized. Defects become hard to be traced at the compile time as all variables share the same namespace and might conflict with each other. With growing application, JavaScript code becomes bigger and harder to manage.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;u&gt;Lot of DOM manipulation:&lt;/u&gt;&amp;nbsp;SPA heavily rely on JavaScript to manipulate DOM tree to update the content of the page. This brings its own challenges as jQuery has really made selecting and manipulating DOM tree very easy but failed to convey the message that probably the re painting HTML page is the most expensive task. Developer tend to read directly from the DOM tree and make changes back to it in the increments. This, probably is not the most efficient way of doing it as in one event, we might read and update the same element several times.&lt;/li&gt;
&lt;li&gt;&lt;u&gt;Read and Update:&lt;/u&gt;&amp;nbsp;JavaScript code is used to set the values in the HTML controls and save the changes back to server by reading back the values from the controls introduces lots of JavaScript code lines. In vanilla JavaScript there are always two or more lines of code associated with each HTML control for the same action and if the number of controls are more, it increases the JavaScript code making it harder to manage the code base.&lt;/li&gt;
&lt;li&gt;&lt;u&gt;Testability:&lt;/u&gt;&amp;nbsp;One of the easy way of managing code base is by dividing the code into small manageable modules by functionality and test it thoroughly. But it is difficult to unit test modules if they have any dependencies on any other modules. Since JavaScript by default does not support dependency injection and we use concrete objects, it means they should be up and running too. Also dependencies like AJAX calls are hard to mock. This causes lot of untested code in the main app. This also reduces our traceability with no way to track any changes in the code blocks.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;u&gt;Browser Navigation:&lt;/u&gt;&amp;nbsp;For SPA, AJAX calls are used to interact with the server, which does not trigger any URL change. This way user can change the main content of the HTML application using AJAX and pretend that next section is loaded with responsive behavior. But this causes issue as it breaks the traditional behavior of the browser navigation. Ajax calls don&#39;t update the URL history, so in attempt to go back to last page using browser navigation, this might take user to previous register page in browser history which might not what user is expecting. To over come this issue, &quot;#&quot; are used in the URL to depict URL change ( as any change in the URL after &quot;#&quot; does not trigger browser to reload the page. but it gets registered in the browser history) and design some pattern to make AJAX call on/with/after URL change. This is also know as deep linking, but to master deep linking and make it in all browser, its very difficult. Also hard to test all types of scenarios.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
There are many good libraries which have changed the way applications are written using JavaScript like&lt;/div&gt;
&lt;div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;jQuery (famous for DOM manipulation)&lt;/li&gt;
&lt;li&gt;KnockOut (famous for MVVM pattern)&lt;/li&gt;
&lt;li&gt;RequireJS (famous for module loading and dependencies injection)&lt;/li&gt;
&lt;li&gt;etc&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
which solves one particular problem of building web application in a excellent way but not as one framework. They all can be clubbed together to work with each other but they were not designed to do so. And there is always duplicate functionality b/w there libraries as they all try to go little extra mile to sell themselves.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Why AngularJS?&lt;/b&gt;&lt;br /&gt;
Like I described earlier, Angular is complete framework which takes care of all the features required for the development of the SPA application, plus its extendable. Here are the feature list&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;u&gt;Directives:&lt;/u&gt;&amp;nbsp;In AngularJS terms, directives are making HTML smarter. Directives can be specified as tags, attributes or classes like ng-view, ng-repeact etc which makes HTML declarative. It also makes HTML code reusable. We can extend default set directives provided in core Angular for our application. During compile time, it looks for directive keys and executes the code to update the HTML as specified in the link function. This will update the specified HTML in template as required by the directive. This helps the keep the DOM manipulation separated from business rules.&lt;/li&gt;
&lt;li&gt;&lt;u&gt;Supports DI:&lt;/u&gt;&amp;nbsp;This is one of the biggest selling point of the AngularJS, supporting Dependency Injection. In Angular, we can create small modules aka services, which can be injected in the controllers, directives or other services. This allows us to mock the services during unit testing and test the actual unit of work without any dependency. By creating services, code can be reused in different modules and it does not interfere with the main business logic of the application.&lt;/li&gt;
&lt;li&gt;&lt;u&gt;Supports MVC:&lt;/u&gt;&amp;nbsp;Angular supports MVC pattern in the development of the application. We need to register controllers either in the config associated with the URL (which is appended after &quot;#&quot; in URL) or we can specify it in the HTML with supported attribute (called directives) i.e. &quot;ng-controller&quot;. Controller is the place where we set the scope which is the view model angular uses to update the HTML template to create the view. By this approach we separate the business logic in the controller or service (which can be injected in the controller and then consumed) and DOM manipulation. Angular updates the view for us in the end with the final value of the object after all business rules implemented which avoids continuous redrawing caused by frequent changes.&lt;/li&gt;
&lt;li&gt;&lt;u&gt;Supports Routing:&lt;/u&gt;&amp;nbsp;AngularJS route module helps in browser navigation. It manages the deep linking for us. We can pull the values like id etc from the URL and use in our code.&lt;/li&gt;
&lt;li&gt;&lt;u&gt;Testability:&lt;/u&gt;&amp;nbsp;Since angular uses DI to inject different services in the controller to be used along the business logic, this approach helps us to keep the code mode testable as we can mock these services to test our business logic behavior.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
The best part of AngularJS is that all these feature are extendable based on our project requirements. We can choose which module to be used in the application. This helps us to keep the 3rd party code light weight and to only include pieces we need for development.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Happy coding ...&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/1916283121305925231/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2014/05/what-is-angularjs-and-why-angularjs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/1916283121305925231'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/1916283121305925231'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2014/05/what-is-angularjs-and-why-angularjs.html' title='What is AngularJS? ... And why AngularJS?'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-4755162553722653655</id><published>2013-11-24T09:48:00.003-05:00</published><updated>2013-11-24T09:48:59.858-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><category scheme="http://www.blogger.com/atom/ns#" term="Project Euler"/><title type='text'>Project Euler - Problem 4 in F#</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div id=&quot;content&quot; style=&quot;background-color: white; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 14px; margin: 40px auto; max-width: 1000px; padding: 10px;&quot;&gt;
&lt;h2 style=&quot;color: #6b4e3d; font-family: Arial, helvetic, sans-serif; margin: 0px; padding: 10px 0px 5px;&quot;&gt;
Largest palindrome product&lt;/h2&gt;
&lt;div class=&quot;info&quot; style=&quot;cursor: help; margin-bottom: 10px; position: relative; width: 200px;&quot;&gt;
&lt;h3 style=&quot;color: #666666; font-family: &#39;Courier New&#39;, monospace; margin: 0px;&quot;&gt;
Problem 4&lt;/h3&gt;
&lt;/div&gt;
&lt;div class=&quot;problem_content&quot; role=&quot;problem&quot; style=&quot;border-color: rgb(221, 221, 221) rgb(170, 170, 170) rgb(170, 170, 170) rgb(221, 221, 221); border-style: solid; border-width: 1px; font-size: 16px; padding: 10px;&quot;&gt;
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91&amp;nbsp;&lt;img alt=&quot;×&quot; border=&quot;0&quot; height=&quot;9&quot; src=&quot;http://projecteuler.net/images/symbol_times.gif&quot; style=&quot;border: 0px; vertical-align: middle;&quot; width=&quot;9&quot; /&gt;99.&lt;br /&gt;
Find the largest palindrome made from the product of two 3-digit numbers.&lt;/div&gt;
&lt;br /&gt;
For this problem, we need to iterate through all the 3 digits number and get there products. Here is the solutions&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;
    // function to flip the existing number to reverse the digits 
    let reverseNumber n =
        // recurring function to create new number to flip the 
        // existing the number digit one at a time
        let rec loop newNum = function
            // if the new number is 0
            // return the new created number as it is
            |0 -&amp;gt; newNum
            // if number is not 0
            // recall the function with new number * 10 and adding modules 
            // of number dividing by 10.
            // return update old number by dividing by 10 
            |x -&amp;gt; loop (newNum * 10 + x % 10) (x/10)    
        loop 0 n

    // check if the number is palindrome
    let isPalindrome = function
        // if number is equal to reversed number then its palindrome, 
        // return true
        | x  when x = reverseNumber x -&amp;gt; true
        // else return false
        | _ -&amp;gt; false

    // function to get the max palindrome number of multiplication
    // of two numbers between the limits
    let maxPalindromeNumber lowerLimit upperLimit =
        // create the seq of all the palidrome numbers create 
        // by multiple two numbers between the limits
        let numbers = seq {
            // get first number from the loop
            for i = lowerLimit to upperLimit do
                // get the second number from the loop
                for j = lowerLimit to upperLimit do
                    // multiple both the numeber
                    let z = i * j
                    // and check if number is palindrome
                    if isPalindrome z then
                        // if yes, return the number to seq else 
                        // move back to new numbers in the loop
                        yield z
        }
        // return the max number from the seq
        Seq.max numbers

    // create diagnostics stopwatch
    let sw = System.Diagnostics.Stopwatch()
    // start the stopwatch
    sw.Start() 
    // call function to get max palindrome number product of two numbers 
    // between 100 and 900
    let number = maxPalindromeNumber 100 999
    // stop the stopwatch
    sw.Stop()
    
    // print number
    printfn &quot;multple of 3 digit resulting %d  - (with processing time %A)&quot; number sw.ElapsedMilliseconds
&lt;/code&gt; &lt;/pre&gt;
&lt;br /&gt;
Code is pretty self explanatory with comments. The avg time of the solution is 177ms&lt;br /&gt;
&lt;br /&gt;
Please feel free to leave you feedback, whats good in the blogs and where i can improve.&lt;br /&gt;
&lt;br /&gt;
Thanks and Happy CODING .... :)&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/4755162553722653655/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2013/11/project-euler-problem-4-in-f.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/4755162553722653655'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/4755162553722653655'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2013/11/project-euler-problem-4-in-f.html' title='Project Euler - Problem 4 in F#'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-337359133367934305</id><published>2013-11-23T17:38:00.000-05:00</published><updated>2013-11-23T17:38:40.840-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><category scheme="http://www.blogger.com/atom/ns#" term="Project Euler"/><title type='text'>Project Euler - Problem 3 in F#</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;background-color: white; color: #6b4e3d; font-family: Arial, helvetic, sans-serif; margin: 0px; padding: 10px 0px 5px;&quot;&gt;
Largest prime factor&lt;/h2&gt;
&lt;div class=&quot;info&quot; style=&quot;background-color: white; cursor: help; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 14px; margin-bottom: 10px; position: relative; width: 200px;&quot;&gt;
&lt;h3 style=&quot;color: #666666; font-family: &#39;Courier New&#39;, monospace; margin: 0px;&quot;&gt;
Problem 3&lt;/h3&gt;
&lt;/div&gt;
&lt;div class=&quot;problem_content&quot; role=&quot;problem&quot; style=&quot;background-color: white; border-color: rgb(221, 221, 221) rgb(170, 170, 170) rgb(170, 170, 170) rgb(221, 221, 221); border-style: solid; border-width: 1px; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 16px; padding: 10px;&quot;&gt;
The prime factors of 13195 are 5, 7, 13 and 29.&lt;br /&gt;
What is the largest prime factor of the number 600851475143 ?&lt;/div&gt;
&lt;br /&gt;
Here is my Solution #1&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;    &lt;/code&gt;&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;    (**********************************
    Solution 1 
    ***********************************
    slow solution as it iterates through all the numbers
    **********************************)

    let theNumber = 600851475143I //13195

    let rec LargestPrimeFactorial (x: bigint) (y:bigint) = 
        match x, y with
            | u, t when u = t -&amp;gt; u
            | c, d when c%d = 0I -&amp;gt; 
                match c with
                    | m when m = theNumber -&amp;gt; LargestPrimeFactorial (m/d) 2I
                    | n -&amp;gt; LargestPrimeFactorial theNumber ((theNumber/n)+1I)
            | e, f -&amp;gt; LargestPrimeFactorial e (f+1I)
            | a, b when a = b -&amp;gt; a
            | _, _ -&amp;gt; failwith &quot;not valid option&quot;

    let sw = System.Diagnostics.Stopwatch()
    sw.Start()  
    let primeFactorNo = LargestPrimeFactorial theNumber 2I
    sw.Stop()
    printfn &quot;%A - (with processing time %A)&quot; primeFactorNo  sw.ElapsedMilliseconds

&lt;/code&gt;&lt;/blockquote&gt;
&lt;/pre&gt;
&lt;br /&gt;
In this solution, i try to iterates through all the numbers which is not so great solution for the huge numbers.&lt;br /&gt;
LargestPrimeFactorial takes two parameters, one the number we are finding factorial for and second number we are checking is divisor or not. Here are match condition checks&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;background-color: #eeeeee; font-family: monospace; font-size: 12px; line-height: 14px; white-space: pre;&quot;&gt;| u, t when u = t -&amp;gt; u&lt;/span&gt;: If both the numbers are same then, return the prime number&lt;/li&gt;
&lt;li&gt;&lt;code style=&quot;background-color: #eeeeee; font-size: 12px; line-height: 14px; white-space: pre; word-wrap: normal;&quot;&gt;| c, d when c%d = 0I -&amp;gt; &lt;/code&gt;: If second number is factor of first number, then we try to find the factors for the divisor to check if that&#39;s a prime number or not. we call the same function with different parameters to find is its a prime number or not.&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: #eeeeee; font-family: monospace; font-size: 12px; line-height: 14px; white-space: pre;&quot;&gt;| e, f -&amp;gt; LargestPrimeFactorial e (f+1I)&lt;/span&gt;: If number is not divisor then recall the function with new incremented number to find the largest prime number divisor.&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: #eeeeee; font-family: monospace; font-size: 12px; line-height: 14px; white-space: pre;&quot;&gt;| _, _ -&amp;gt; failwith &quot;not valid option&quot;&lt;/span&gt;: If no condition is matched, fail with exception.&lt;/li&gt;
&lt;/ul&gt;
We this process is very slow. This is a basic logic to find the largest prime factor by dividing the number with each and every number to find all the factors and then check if the factorial number is prime number of not in the same manner. This logic on avg took 59590 ms.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Here is my Solution #2&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 653px;&quot;&gt;&lt;code style=&quot;word-wrap: normal;&quot;&gt;    &lt;/code&gt;&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;code style=&quot;word-wrap: normal;&quot;&gt;    

    (**********************************
    Solution 2
    ***********************************
    Better solution to find all the divisors
    if n / x = y, obviously both x and y are factors, so I don&#39;t have to probe y anymore
    If I start probing from 2 going up, I can stop probing when I have reached \sqrt n. In fact, any number bigger than \sqrt n must have been already found probing a smaller number.
    Suppose for example that we have to factor the number 36 (one of the triangle number
    **********************************)

    let theNumber = 600851475143I //13195

    let divides (x:bigint) (y:bigint) = (x % y = 0I)

    let rec GetAllFactors (num:bigint) (index:bigint) factors = 
        if (divides num index) then
            let y = num / index
            if index &amp;lt; y then
                GetAllFactors num (index + 1I) (index::y::factors)
            else if (y = index) then
                (index::factors)
            else 
                factors
        else if index &amp;gt; bigint (sqrt (float num)) then
            factors
        else 
            GetAllFactors num (index + 1I) factors

    let rec PrimeNumber = function
        | [] -&amp;gt; 0
        | h::t -&amp;gt; 
            let factors = GetAllFactors h 2I []
            if(factors.Length = 0) then
                int h
            else 
                PrimeNumber t

    let rec LargestPrimeFactorial (x: bigint) = 
        let factorList = GetAllFactors x 2I []
        let factorRevList = factorList
                                |&amp;gt; List.sort 
                                |&amp;gt; List.rev

        let largestPrimeNumber = PrimeNumber factorRevList
        largestPrimeNumber        
    
    let sw = System.Diagnostics.Stopwatch()
    sw.Start()    
    let primeFactorNo = LargestPrimeFactorial theNumber
    sw.Stop()
&lt;/code&gt;&lt;/blockquote&gt;
&lt;/pre&gt;
&lt;br /&gt;
In this solution, i have used better solution to find all the divisors. According to new formula, if &lt;i&gt;n&lt;/i&gt; / &lt;i&gt;x&lt;/i&gt; = &lt;i&gt;y&lt;/i&gt;, obviously both &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; are factors, so I don&#39;t have to probe y anymore. If I start probing from 2 going up, I can stop probing when I have reached sqrt &lt;i&gt;n&lt;/i&gt;. In fact, any number bigger than sqrt &lt;i&gt;n&lt;/i&gt; must have been already found probing a smaller number. Here is the explanation of the written code&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;background-color: #eeeeee; font-family: monospace; font-size: 12px; line-height: 14px; white-space: pre;&quot;&gt;GetAllFactors&lt;/span&gt;: Gets all the factors of a number in the array&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: #eeeeee; font-family: monospace; font-size: 12px; line-height: 14px; white-space: pre;&quot;&gt;PrimeNumber&lt;/span&gt;: Checks if the number is prime or not&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: #eeeeee; font-family: monospace; font-size: 12px; line-height: 14px; white-space: pre;&quot;&gt;LargestPrimeFactorial&lt;/span&gt;: Get the largest number from the factors list.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
This logic on avg took 2900 ms.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Please feel free to leave feedback ... whats good in the post and where i can improve.&lt;br /&gt;
&lt;br /&gt;
Thanks and happy coding&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/337359133367934305/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2013/11/project-euler-problem-3-in-f.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/337359133367934305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/337359133367934305'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2013/11/project-euler-problem-3-in-f.html' title='Project Euler - Problem 3 in F#'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-517411214141702193</id><published>2013-10-14T09:55:00.002-04:00</published><updated>2013-10-14T09:55:42.403-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>JavaScript Crash Course</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Here is a small JavaScript crash course which i wrote while going thru one of JavaScript&#39;s online open courses. This PDf has been very helpful to quick refresh my Javascript fundamentals whenever needed.&lt;br /&gt;
&lt;br /&gt;
Hope this will be helpful to you all too. Please click&amp;nbsp;&lt;a href=&quot;https://docs.google.com/file/d/0B0z8Zj3JDV0-RlpzdkZXd2RTeTg/edit?usp=drive_web&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;&amp;nbsp;to download this PDF file.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/517411214141702193/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2013/10/javascript-crash-course.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/517411214141702193'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/517411214141702193'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2013/10/javascript-crash-course.html' title='JavaScript Crash Course'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-4690314440350399682</id><published>2013-10-13T18:33:00.001-04:00</published><updated>2013-10-13T18:44:12.116-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Angular"/><category scheme="http://www.blogger.com/atom/ns#" term="Angular Directives"/><category scheme="http://www.blogger.com/atom/ns#" term="Angular Services"/><category scheme="http://www.blogger.com/atom/ns#" term="AngularJS"/><title type='text'>Angular Directive VS Service usage</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Angular is built from ground up keeping separation of concern, modularity and testing in mind. One of the frequently asked question in AngularJS is where to use Directives and Services.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Directives&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Directives are a way to teach HTML new tricks. During DOM compilation directives are matched against the HTML and executed. This allows directives to register behavior, or transform the DOM -&amp;nbsp;&lt;/span&gt;(&lt;i&gt;angularjs.org/guide/directive&lt;/i&gt;)&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: x-small; line-height: 18px;&quot;&gt;As mentioned in the definition, Directives are&amp;nbsp;strictly for the DOM manipulation only. Directives are genius way to make DOM more intelligent e.g. we can create a directive which creates new element with node name as &quot;&lt;/span&gt;&lt;i style=&quot;color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: small; line-height: 18px;&quot;&gt;tab&lt;/i&gt;&lt;span style=&quot;color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: x-small; line-height: 18px;&quot;&gt;&quot; which angular at run time which resolve as HTML. This gives HTML a new meaning by creating new reusable tags and also gives us one code place to explain what tag &quot;&lt;/span&gt;&lt;i style=&quot;color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: small; line-height: 18px;&quot;&gt;tab&lt;/i&gt;&lt;span style=&quot;color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: x-small; line-height: 18px;&quot;&gt;&quot; are and easy to maintain.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Services&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;color: #333333; font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: x-small;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;A service is any functionality which can be abstracted and then called by different functions e.g.&lt;i&gt; $http&lt;/i&gt;, &lt;i&gt;$routeProvider&lt;/i&gt;, etc. These services are needed to be injected in the controllers or other services using them to avoid direct reference to the functions. On injecting, these services are initialized and then can be used in the code without be directly object of the function. This is good code practice as we can mock the services for the test.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #333333; font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: x-small;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #333333; font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: x-small;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;Ideally, directives should be strictly used for any UI view manipulation and services are abstracted&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;functionalities which can be mocked for unit tests. Service should not be used for any DOM manipulation or event binding.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #333333; font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: x-small;&quot;&gt;&lt;span style=&quot;line-height: 18px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/4690314440350399682/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2013/10/angular-directive-vs-service-usage.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/4690314440350399682'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/4690314440350399682'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2013/10/angular-directive-vs-service-usage.html' title='Angular Directive VS Service usage'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-5456279688714168743</id><published>2013-10-01T15:42:00.002-04:00</published><updated>2013-10-01T15:42:41.451-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><category scheme="http://www.blogger.com/atom/ns#" term="Project Euler"/><title type='text'>Project Euler - Problem 2 in F#</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;background-color: white; color: #6b4e3d; font-family: Arial, helvetic, sans-serif; margin: 0px; padding: 10px 0px 5px;&quot;&gt;
Even Fibonacci numbers&lt;/h2&gt;
&lt;div class=&quot;info&quot; style=&quot;background-color: white; cursor: help; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 14px; margin-bottom: 10px; position: relative; width: 200px;&quot;&gt;
&lt;h3 style=&quot;color: #666666; font-family: &#39;Courier New&#39;, monospace; margin: 0px;&quot;&gt;
Problem 2&lt;/h3&gt;
&lt;/div&gt;
&lt;div class=&quot;problem_content&quot; role=&quot;problem&quot; style=&quot;background-color: white; border-color: rgb(221, 221, 221) rgb(170, 170, 170) rgb(170, 170, 170) rgb(221, 221, 221); border-style: solid; border-width: 1px; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 16px; padding: 10px;&quot;&gt;
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...&lt;/div&gt;
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.&lt;/div&gt;
&lt;br /&gt;
Here is my solution&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #1e1e1e; color: #dadada; font-family: Consolas; font-size: 13;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #608b4e;&quot;&gt;//&amp;nbsp;Create&amp;nbsp;a&amp;nbsp;mutable&amp;nbsp;list,&amp;nbsp;so&amp;nbsp;that&amp;nbsp;we&amp;nbsp;can&amp;nbsp;add&amp;nbsp;elements&amp;nbsp;&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #608b4e;&quot;&gt;//&amp;nbsp;(this&amp;nbsp;corresponds&amp;nbsp;to&amp;nbsp;standard&amp;nbsp;.NET&amp;nbsp;&#39;List&amp;lt;T&amp;gt;&#39;&amp;nbsp;type)&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;let&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;l&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;ResizeArray&lt;/span&gt;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;&amp;lt;&lt;/span&gt;_&lt;span style=&quot;color: #b4b4b4;&quot;&gt;&amp;gt;&lt;/span&gt;([&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;])
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;let&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;rec&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;fabonacci&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;b&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;upperLimit&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;=&lt;/span&gt;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;match&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;a&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;b&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;with&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;|&amp;nbsp;_,&amp;nbsp;_&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;when&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;b&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;&amp;lt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;upperLimit&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;-&amp;gt;&lt;/span&gt;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;let&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;c&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;b&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;l&lt;/span&gt;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: white;&quot;&gt;Add&lt;/span&gt;(&lt;span style=&quot;color: white;&quot;&gt;c&lt;/span&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;fabonacci&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;b&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;c&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;upperLimit&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;|&amp;nbsp;_&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;-&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;l&lt;/span&gt;
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;let&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;sumOfEven&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;=&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(&lt;span style=&quot;color: white;&quot;&gt;fabonacci&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;4000000&lt;/span&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;|&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;List&lt;/span&gt;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: white;&quot;&gt;ofSeq&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;|&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;Seq&lt;/span&gt;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: white;&quot;&gt;filter&lt;/span&gt;&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;fun&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;x&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;-&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;x&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;%&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;|&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;Seq&lt;/span&gt;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: white;&quot;&gt;sum&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;br /&gt;
Since its dynamic seq we are creating which depends on the last two numbers, we need a mutable list which we can populate according to our need and logic. For Fibonacci, we need to have access to previous two numbers in the list to generate new one.&lt;br /&gt;
&lt;br /&gt;
This solution is flexible too with the upper limit, so this logic can be used anywhere to create the Fibonacci sequence with any upper bound. First step is to create Fibonacci sequence with the upper bound and initial number to kick start the sequence.Once seq is created up to desired upper bound, we are left with filtering of the sequence for even numbers only and get their sum.&lt;br /&gt;
&lt;br /&gt;
Please leave your feedback and happy coding.&amp;nbsp;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/5456279688714168743/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2013/10/project-euler-problem-2-in-f.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/5456279688714168743'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/5456279688714168743'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2013/10/project-euler-problem-2-in-f.html' title='Project Euler - Problem 2 in F#'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-2936372447312370552</id><published>2013-09-29T15:37:00.000-04:00</published><updated>2013-09-29T15:37:00.889-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><category scheme="http://www.blogger.com/atom/ns#" term="Project Euler"/><title type='text'>Project Euler - Problem 1 in F#</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;background-color: white; color: #6b4e3d; font-family: Arial, helvetic, sans-serif; margin: 0px; padding: 10px 0px 5px;&quot;&gt;
Multiples of 3 and 5&lt;/h2&gt;
&lt;div class=&quot;info&quot; style=&quot;background-color: white; cursor: help; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 14px; margin-bottom: 10px; position: relative; width: 200px;&quot;&gt;
&lt;h3 style=&quot;color: #666666; font-family: &#39;Courier New&#39;, monospace; margin: 0px;&quot;&gt;
Problem 1&lt;/h3&gt;
&lt;/div&gt;
&lt;div class=&quot;problem_content&quot; role=&quot;problem&quot; style=&quot;background-color: white; border-color: rgb(221, 221, 221) rgb(170, 170, 170) rgb(170, 170, 170) rgb(221, 221, 221); border-style: solid; border-width: 1px; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 16px; padding: 10px;&quot;&gt;
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.&lt;br /&gt;
Find the sum of all the multiples of 3 or 5 below 1000.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Here is my solution&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre style=&quot;background: #1e1e1e; color: gainsboro; font-family: Consolas; font-size: 13;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #608b4e;&quot;&gt;//&amp;nbsp;Option&amp;nbsp;1&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;let&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;sumOfNoDivisbleBy3or5UnderN&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;n&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;=&lt;/span&gt;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;i&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;..&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;-&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;i&lt;/span&gt;]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;|&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;Seq&lt;/span&gt;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: white;&quot;&gt;filter&lt;/span&gt;&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;fun&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;x&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;-&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #b5cea8;&quot;&gt;3&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;||&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #b5cea8;&quot;&gt;5&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;|&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;Seq&lt;/span&gt;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: white;&quot;&gt;sum&lt;/span&gt;
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;let&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;sumOfNoDivisbleBy3or5Under10&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;sumOfNoDivisbleBy3or5UnderN&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;10&lt;/span&gt;
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;let&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;sumOfNoDivisbleBy3or5Under1000&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;sumOfNoDivisbleBy3or5UnderN&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1000&lt;/span&gt;
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;printfn&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #d69d85;&quot;&gt;&quot;The&amp;nbsp;sum&amp;nbsp;of&amp;nbsp;all&amp;nbsp;the&amp;nbsp;multiples&amp;nbsp;of&amp;nbsp;3&amp;nbsp;or&amp;nbsp;5&amp;nbsp;is&amp;nbsp;%d&quot;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;sumOfNoDivisbleBy3or5Under1000&lt;/span&gt;
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #608b4e;&quot;&gt;//&amp;nbsp;Option&amp;nbsp;2&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;let&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;sumOfFilteredSeq&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;filterCri&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;n&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;=&lt;/span&gt;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;seq&lt;/span&gt;&amp;nbsp;{&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;for&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;i&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;..&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;-&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;filterCri&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;i&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;then&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;i&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;else&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;|&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;Seq&lt;/span&gt;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: white;&quot;&gt;sum&lt;/span&gt;
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;let&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;filteredSeqOf3or5&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;sumOfFilteredSeq&lt;/span&gt;&amp;nbsp;(&lt;span style=&quot;color: #569cd6;&quot;&gt;fun&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;x&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;-&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #b5cea8;&quot;&gt;3&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;||&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #b5cea8;&quot;&gt;5&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;let&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;sumOfNoUnder10&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;filteredSeqOf3or5&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;10&lt;/span&gt;
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #569cd6;&quot;&gt;let&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;sumOfNoUnder1000&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b4b4b4;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;filteredSeqOf3or5&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1000&lt;/span&gt;
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;printfn&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #d69d85;&quot;&gt;&quot;The&amp;nbsp;sum&amp;nbsp;of&amp;nbsp;all&amp;nbsp;the&amp;nbsp;multiples&amp;nbsp;of&amp;nbsp;3&amp;nbsp;or&amp;nbsp;5&amp;nbsp;is&amp;nbsp;%d&quot;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: white;&quot;&gt;sumOfNoUnder1000&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Here i have specified two solutions.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Options 1 is hard coded with the filter criteria and is only flexible &amp;nbsp;in changing the upper bound of the List where as option 2 is flexible in both upper bound as well as the filter criteria&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/2936372447312370552/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2013/09/project-euler-problem-1-in-f.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/2936372447312370552'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/2936372447312370552'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2013/09/project-euler-problem-1-in-f.html' title='Project Euler - Problem 1 in F#'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-8741684020335017934</id><published>2012-04-10T17:18:00.001-04:00</published><updated>2012-04-10T17:18:05.444-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DisplateTemplates"/><category scheme="http://www.blogger.com/atom/ns#" term="EditorTemplates"/><category scheme="http://www.blogger.com/atom/ns#" term="MVC Templates"/><category scheme="http://www.blogger.com/atom/ns#" term="MVC4"/><category scheme="http://www.blogger.com/atom/ns#" term="Partial View"/><title type='text'>Partial View Vs. Display/Editor Templates</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; color: #333333; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; margin-bottom: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
ASP.net MVC provides two different options to create re-usable components&lt;/div&gt;
&lt;ul style=&quot;color: #333333; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; list-style-position: outside; margin-bottom: 10px; margin-left: 0px; margin-top: 0px; padding-left: 3em; padding-top: 0px;&quot;&gt;
&lt;li style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Partial Views&lt;/li&gt;
&lt;li style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Display/Editor Templates&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; color: #333333; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; margin-bottom: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
But whats the different between both of them and what advantage one has got over the other.&lt;/div&gt;
&lt;h5 style=&quot;font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 1.1em; margin-bottom: 0.1em; margin-left: 0px; margin-right: 0px; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;strong&gt;Difference between Display and Editor Templates:&amp;nbsp;&lt;/strong&gt;&lt;/h5&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; color: #333333; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; margin-bottom: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
Display templates and Editor templates are model driven templates but only differ by the convention that display should only render read only html like divs, labels or spans etc where are editor should render editable html with forms, input controls, etc. Developers are the one whole create these templates and there is no validation which prevent us to create templates in the opposite order. It is the convention over configuration policy which drives MVC to follow a specific standardize pattern and sticking to this will ensure that no matter what you pass into&amp;nbsp;&lt;strong&gt;Display&amp;nbsp;&lt;/strong&gt;helper method(s) will always render the same result as expected. Once we specify UIHint on any property, we instructor MVC view engine to render the respective property using given template specified either under&amp;nbsp;&lt;strong&gt;DisplayTemplates&lt;/strong&gt;&amp;nbsp;folder or&amp;nbsp;&lt;strong&gt;EditorTemplates&lt;/strong&gt;&amp;nbsp;folder under shared folder depending whether we want readonly mode (Html.Display) or editable mode (Html.Editor).&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://1.bp.blogspot.com/-yfq4iig1slY/T4SjPldjMFI/AAAAAAAABeg/95Ypo9t_BEI/s1600/DisplayEditortemplates.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-yfq4iig1slY/T4SjPldjMFI/AAAAAAAABeg/95Ypo9t_BEI/s1600/DisplayEditortemplates.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; color: #333333; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; margin-bottom: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; color: #333333; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; margin-bottom: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
Sample ViewModel for the same to&amp;nbsp;demonstrate&amp;nbsp;how we ViewModel can be decorated with attributes to leverage templates rendering thru ViewModels&amp;nbsp;in MVC&lt;/div&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; color: #333333; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; margin-bottom: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;using&lt;/span&gt;&amp;nbsp;System;&lt;/div&gt;
&lt;pre style=&quot;color: #333333; font-size: 13px; line-height: 17px; margin-bottom: 10px; margin-top: 10px; overflow-x: visible; overflow-y: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;using&lt;/span&gt;&amp;nbsp;System.Collections.Generic;
&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;using&lt;/span&gt;&amp;nbsp;System.Linq;
&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;using&lt;/span&gt;&amp;nbsp;System.Web;
&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;using&lt;/span&gt;&amp;nbsp;System.ComponentModel.DataAnnotations;
&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;using&lt;/span&gt;&amp;nbsp;ReferenceImplementation.ViewModels;
 
&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;namespace&lt;/span&gt;&amp;nbsp;ReferenceImplementation.ViewModels
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;&amp;nbsp;&lt;span data-mce-style=&quot;color: #2b91af;&quot; style=&quot;color: #2b91af;&quot;&gt;PersonViewModel&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;nbsp;FirstName&amp;nbsp;{&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;;&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;;&amp;nbsp;}
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;nbsp;LastName&amp;nbsp;{&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;;&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;;&amp;nbsp;}
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span data-mce-style=&quot;color: #2b91af;&quot; style=&quot;color: #2b91af;&quot;&gt;UIHint&lt;/span&gt;(&lt;span data-mce-style=&quot;color: #a31515;&quot; style=&quot;color: #a31515;&quot;&gt;&quot;Int&quot;&lt;/span&gt;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&amp;nbsp;Age&amp;nbsp;{&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;;&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;;&amp;nbsp;}
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span data-mce-style=&quot;color: #2b91af;&quot; style=&quot;color: #2b91af;&quot;&gt;UIHint&lt;/span&gt;(&lt;span data-mce-style=&quot;color: #a31515;&quot; style=&quot;color: #a31515;&quot;&gt;&quot;Date&quot;&lt;/span&gt;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span data-mce-style=&quot;color: #2b91af;&quot; style=&quot;color: #2b91af;&quot;&gt;DatetimeViewModel&lt;/span&gt;&amp;nbsp;DateOfBirth&amp;nbsp;{&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;;&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;;&amp;nbsp;}
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;span data-mce-style=&quot;color: #2b91af;&quot; style=&quot;color: #2b91af;&quot;&gt;UIHint&lt;/span&gt;(&lt;span data-mce-style=&quot;color: #a31515;&quot; style=&quot;color: #a31515;&quot;&gt;&quot;Phone&quot;&lt;/span&gt;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span data-mce-style=&quot;color: #2b91af;&quot; style=&quot;color: #2b91af;&quot;&gt;PhoneViewModel&lt;/span&gt;&amp;nbsp;MobileNumber&amp;nbsp;{&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;;&amp;nbsp;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}&lt;/pre&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; color: #333333; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; margin-bottom: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
By specifying the&amp;nbsp;&lt;span data-mce-style=&quot;color: #2b91af;&quot; style=&quot;color: #2b91af;&quot;&gt;UIHint&amp;nbsp;&lt;/span&gt;attribute on properties in ViewModel, we are instructing MVC to render these properties with the respective templates (depending on its display or editor reference) from the respective folder instead of using standard MVC editor.&lt;/div&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; color: #333333; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; margin-bottom: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
For the view code like the one given below&lt;/div&gt;
&lt;pre style=&quot;color: #333333; font-size: 13px; line-height: 17px; margin-bottom: 10px; margin-top: 10px; overflow-x: visible; overflow-y: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span data-mce-style=&quot;color: maroon;&quot; style=&quot;color: maroon;&quot;&gt;div&lt;/span&gt;&amp;nbsp;&lt;span data-mce-style=&quot;color: red;&quot; style=&quot;color: red;&quot;&gt;class&lt;/span&gt;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;&quot;readonly&quot;&lt;/span&gt;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;@Html.DisplayFor(m =&amp;gt; m.DateOfBirth)&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span data-mce-style=&quot;color: maroon;&quot; style=&quot;color: maroon;&quot;&gt;div&lt;/span&gt;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; color: #333333; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; margin-bottom: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
Since we are using&amp;nbsp;&lt;strong&gt;Display&lt;/strong&gt;&amp;nbsp;helper method, MVC will look for the Date template under DisplayTemplates folder and &amp;nbsp;for the view code given below&lt;/div&gt;
&lt;pre style=&quot;color: #333333; font-size: 13px; line-height: 17px; margin-bottom: 10px; margin-top: 10px; overflow-x: visible; overflow-y: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span data-mce-style=&quot;color: maroon;&quot; style=&quot;color: maroon;&quot;&gt;div&lt;/span&gt;&amp;nbsp;&lt;span data-mce-style=&quot;color: red;&quot; style=&quot;color: red;&quot;&gt;class&lt;/span&gt;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;&quot;editale&quot;&lt;/span&gt;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;@Html.EditorFor(m =&amp;gt; m.Phone)&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span data-mce-style=&quot;color: maroon;&quot; style=&quot;color: maroon;&quot;&gt;div&lt;/span&gt;&lt;span data-mce-style=&quot;color: blue;&quot; style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; color: #333333; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; margin-bottom: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
MVC will look for template under EditorTemplates folder for the&amp;nbsp;&lt;strong&gt;Editor&lt;/strong&gt;&amp;nbsp;helper method.&lt;/div&gt;
&lt;h4 style=&quot;font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 1.2em; margin-bottom: 0.3em; margin-left: 0px; margin-right: 0px; margin-top: 1.2em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
Difference between Partial View and Display/Editor Templates&lt;/h4&gt;
&lt;div data-mce-style=&quot;margin-left: 30.0px;&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; color: #333333; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; margin-bottom: 10px; margin-left: 30px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
By convention, Partial Views are considered to be View Centeric and MVC Templates are considered to be Model Centeric. This means that templates are more dependent on the view model and way they are rendered depends a lot on their properties but same is not true for the partial view as you are more concerned in choosing the correct partial view.&lt;/div&gt;
&lt;div data-mce-style=&quot;margin-left: 30.0px;&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; color: #333333; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; margin-bottom: 10px; margin-left: 30px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
Partial View differs from Templates in the way they render Id&#39;s from the ViewModels. Partial view render the element name as it is but MVC Templates adhere to model hierarchies when rendering HTML helpers. e.g if you have a &quot;Bar&quot; object on your &quot;Foo&quot; model, the HTML elements for &quot;Bar&quot; will be rendered with &quot;&lt;strong&gt;Foo.Bar.ElementName&lt;/strong&gt;&quot;, whilst a partial will have &quot;&lt;strong&gt;ElementName&lt;/strong&gt;&quot;.&lt;/div&gt;
&lt;div data-mce-style=&quot;margin-left: 30.0px;&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; color: #333333; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; margin-bottom: 10px; margin-left: 30px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
MVC Templates are more robust and smart. If you had a List&amp;lt;T&amp;gt; of something in your ViewModel, you could use&amp;nbsp;&lt;span class=&quot;lit&quot; data-mce-style=&quot;color: #800000;&quot; style=&quot;color: maroon;&quot;&gt;@Html&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;typ&quot; data-mce-style=&quot;color: #2b91af;&quot; style=&quot;color: #2b91af;&quot;&gt;DisplayFor&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;m&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;&amp;nbsp;m&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;typ&quot; data-mce-style=&quot;color: #2b91af;&quot; style=&quot;color: #2b91af;&quot;&gt;CollectionOfFoo&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;)&lt;/span&gt;, MVC templates are smart enough to see it as a collection and render out the single display for each item as opposed to a Partial, which would require an explicit for loop.&lt;/div&gt;
&lt;div data-mce-style=&quot;margin-left: 30.0px;&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; color: #333333; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; margin-bottom: 10px; margin-left: 30px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
Templates are passed with additional information that partial views are not, in particular you&amp;nbsp;receive&amp;nbsp;ModelMetadata, such as that created by attributes. ModelMetadata are part of ViewData which is also accessible in partial view but are null as its only populated in templates ().&lt;/div&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; color: #333333; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;span data-mce-style=&quot;color: #444444;&quot; style=&quot;color: #444444;&quot;&gt;&lt;span data-mce-style=&quot;color: #ff0000;&quot; style=&quot;color: red;&quot;&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;/span&gt;&amp;nbsp;Templates are partials which adhere to a specific convention. The situations which make templates better or worse than old partials are almost strictly dependent on whether or not the convention is worth adherence in your application&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/8741684020335017934/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2012/04/partial-view-vs-displayeditor-templates.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/8741684020335017934'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/8741684020335017934'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2012/04/partial-view-vs-displayeditor-templates.html' title='Partial View Vs. Display/Editor Templates'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-yfq4iig1slY/T4SjPldjMFI/AAAAAAAABeg/95Ypo9t_BEI/s72-c/DisplayEditortemplates.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-2213515151512477503</id><published>2012-04-09T22:05:00.002-04:00</published><updated>2012-04-09T22:05:48.809-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.net"/><category scheme="http://www.blogger.com/atom/ns#" term="Bundle"/><category scheme="http://www.blogger.com/atom/ns#" term="Bundling"/><category scheme="http://www.blogger.com/atom/ns#" term="CSS"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="Minification"/><category scheme="http://www.blogger.com/atom/ns#" term="MVC4"/><category scheme="http://www.blogger.com/atom/ns#" term="Performance"/><title type='text'>Bundle and Minification in MVC4</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;


&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;What is meant by MINIFICATION?&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;As&amp;nbsp;described&amp;nbsp;in wiki ...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b style=&quot;background-color: white; font-size: 13px; line-height: 19px; text-align: -webkit-auto;&quot;&gt;&quot;&lt;/b&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;line-height: 19px;&quot;&gt;&lt;i&gt;&lt;b&gt;Minification &lt;/b&gt;(also minimisation or minimization), in computer programming languages and especially JavaScript, is the process of removing all unnecessary characters from source code, without changing its functionality. These unnecessary characters usually include white space characters, new line characters, comments, and sometimes block delimiters, which are used to add readability to the code but are not required for it to execute.&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;This is very helpful as we can reduce the size of the javascript file to be downloaded to the client browser from the server which reduces the data to be downloaded and increases the performance&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;


&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;What is meant by BUNDLING?&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Bundling is the process of combining all the javascript files into one file so that client browser has to make only one request to the server to download all the files in go. For example, max browser can only process 2 request at a given instance (possibly has increased with the modern browsers). If we have more number of files then they have to wait for browser to request from server once the previous requests are complete which creates delay for the page to get complete resources before it is ready. On the other hand bundling process bundle up all the js files needed to be downloaded into one and does not have to wait for the server to process other request hence increasing the performance of the application. Same can be done for the CSS files.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Bundling and minification go well together as we can reduce the size of the file by minification and bundle up all the files like js and css in there respective file types to reduce the calls to the server.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Figure 1.1 shows a page being loaded with multiple script files. Total time to download all the files and before DOM ready event is fired is 2.14s.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjouLGcO1_mEX9M4ns5nWkgwgn8m31Su24CqD0i4Hu7irzNPE3fTGX6W2U1CCqI0hS12msTnPCtrXBmRNN4jd6UDHcWJaZ3YBsQsJsVtBmzmZZa6H-zf6fIurAv84iCcs2wm0BXny-DyqMx/s1600/ScriptFilesWoBundled&amp;amp;Minified.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;295&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjouLGcO1_mEX9M4ns5nWkgwgn8m31Su24CqD0i4Hu7irzNPE3fTGX6W2U1CCqI0hS12msTnPCtrXBmRNN4jd6UDHcWJaZ3YBsQsJsVtBmzmZZa6H-zf6fIurAv84iCcs2wm0BXny-DyqMx/s400/ScriptFilesWoBundled&amp;amp;Minified.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;Figure 1.1&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Figure 1.2 shows a same page being loaded but this time we are using bundling and minification for the script files. So we have reduced the number of server calls to one and file is loaded in 370ms.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8BMLMpA_lE1IHdMzUTSA8QaKE50lP45Q7593MaXDcIzYLfZfcAnyr-cP3L_U6MoA_AkfYLoEbTjOpOqcWYqLDbDBSRYjfqsIx9R5i7YrSO2Qd7g_r27VEJliH-AWom9Xy33ZiposoV4UA/s1600/ScriptFilesWBundled%2526Minified.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;297&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8BMLMpA_lE1IHdMzUTSA8QaKE50lP45Q7593MaXDcIzYLfZfcAnyr-cP3L_U6MoA_AkfYLoEbTjOpOqcWYqLDbDBSRYjfqsIx9R5i7YrSO2Qd7g_r27VEJliH-AWom9Xy33ZiposoV4UA/s400/ScriptFilesWBundled%2526Minified.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;Figure 1.2&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;

&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Using Bundling and Minification in ASP.net MVC4&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;ASP.net
MVC 4 comes with new feature called bundling and minification.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;mainWebStyle&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Bundle&lt;/span&gt;(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;~/Scripts/libs&quot;&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: #2b91af;&quot;&gt;JsMinify&lt;/span&gt;));&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;mainWebStyle.AddFile(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;~/Scripts/&lt;span style=&quot;background: silver;&quot;&gt;jquery-1.7.1.min.js&lt;/span&gt;&quot;&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;mainWebStyle.AddFile(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;~/Scripts/Knockout-2.0.0.js&quot;&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: #2b91af; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;BundleTable&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;.Bundles.Add(mainWebStyle);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;In
the above example, we can how bundles are created. This this example, we are
bundling up two js file into one lib1 file. we can also bundle all the files in
one folder with the following code.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;mainWebStyle&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Bundle&lt;/span&gt;(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;~/Scripts/libs&quot;&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: #2b91af;&quot;&gt;JsMinify&lt;/span&gt;));&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;mainWebStyle.AddDirectory(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;~/Scripts&quot;&lt;/span&gt;&lt;span style=&quot;background: silver;&quot;&gt;,
&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;*.js&quot;&lt;/span&gt;&lt;span style=&quot;background: silver;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background: silver; color: blue;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;background: silver;&quot;&gt;);&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: #2b91af; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;BundleTable&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;.Bundles.Add(mainWebStyle);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;And
in the view we can refer to &amp;nbsp;bundled file like this.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;src&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;&lt;/span&gt;&lt;span style=&quot;background: yellow;&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;Microsoft.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;~/Scripts/libs&quot;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;)&quot;&lt;/span&gt;&lt;span style=&quot;background: silver;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;text/javascript&quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Microsoft.Web.optimization
help to cache the file on the clients machine and at the same time also adds a
magical versioning number to the file which changes if file is changed, hence
forcing the client to request for new file if file is modified and not refer to
cached file on the client side.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;We
can also use our own minification utility if we dont like the one provided by
the microsoft e.g&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;System;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;System.Collections.Generic;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;System.Linq;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;System.Web;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;Microsoft.Web.Optimization;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;Yahoo.Yui.Compressor;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;namespace&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;MVC4Example&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;YuiJsMinify&lt;/span&gt;&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;IBundleTransform&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt;&amp;nbsp;Process(&lt;span style=&quot;color: #2b91af;&quot;&gt;BundleResponse&lt;/span&gt;&amp;nbsp;bundle)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&amp;nbsp;(bundle&amp;nbsp;==&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;throw&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;ArgumentNullException&lt;/span&gt;(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;bundle&quot;&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bundle.Content&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;JavaScriptCompressor&lt;/span&gt;.Compress(bundle.Content);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bundle.ContentType&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;System;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;System.Collections.Generic;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;System.Linq;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;System.Web;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;Microsoft.Web.Optimization;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;Yahoo.Yui.Compressor;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;namespace&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&lt;span style=&quot;background: silver;&quot;&gt;MVC4Example&lt;/span&gt;&lt;br /&gt;
{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;YuiCssMinify&lt;/span&gt;&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;IBundleTransform&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt;&amp;nbsp;Process(&lt;span style=&quot;color: #2b91af;&quot;&gt;BundleResponse&lt;/span&gt;&amp;nbsp;bundle)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&amp;nbsp;(bundle&amp;nbsp;==&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;throw&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;ArgumentNullException&lt;/span&gt;(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;bundle&quot;&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bundle.Content&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;CssCompressor&lt;/span&gt;.Compress(bundle.Content);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bundle.ContentType&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;text/css&quot;&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;In
the above example, i have used Yahoo Yui compressor dll to minify my javascript
and style files instead of JsMinify and CssMinify.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Please visit the link of the presentation that Scott Gu gave in Netherlands to demo bundling and
minifications and some other new features coming out in MVC 4&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;a href=&quot;http://channel9.msdn.com/Events/TechDays/Techdays-2012-the-Netherlands/2364&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;http://channel9.msdn.com/Events/TechDays/Techdays-2012-the-Netherlands/2364&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Happy
Coding&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/2213515151512477503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2012/04/bundle-and-minification-in-mvc4.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/2213515151512477503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/2213515151512477503'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2012/04/bundle-and-minification-in-mvc4.html' title='Bundle and Minification in MVC4'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjouLGcO1_mEX9M4ns5nWkgwgn8m31Su24CqD0i4Hu7irzNPE3fTGX6W2U1CCqI0hS12msTnPCtrXBmRNN4jd6UDHcWJaZ3YBsQsJsVtBmzmZZa6H-zf6fIurAv84iCcs2wm0BXny-DyqMx/s72-c/ScriptFilesWoBundled&amp;Minified.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-182468871120385105</id><published>2012-02-11T00:47:00.000-05:00</published><updated>2012-02-11T00:47:40.276-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="image"/><category scheme="http://www.blogger.com/atom/ns#" term="image album"/><category scheme="http://www.blogger.com/atom/ns#" term="jquery"/><category scheme="http://www.blogger.com/atom/ns#" term="plugin"/><title type='text'>jQuery Google Plusify</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;I recently created new plugin to imitate Google Plus photo album. I will try to explain&amp;nbsp;briefly how to use this plugin. For demo click &lt;a href=&quot;http://jassra.com/Jquery/ImagePlusify&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;&amp;nbsp;and you can also download full and minified version over here.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;To start with, include minified (for production) or full version (for development) in your page.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-align: -webkit-auto; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small; text-align: left;&quot;&gt;&amp;lt;script type=&lt;span style=&quot;color: #990000;&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt; src=&lt;span style=&quot;color: #990000;&quot;&gt;&quot;&lt;i&gt;&amp;lt;javascript folder path&amp;gt;&lt;/i&gt;/jquery.imagePlusify-1.0.min.js&quot;&lt;/span&gt; &amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Place your div with width and height where you want place your albums.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: -webkit-auto; text-indent: -2px;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;lt;div id=&#39;&lt;/span&gt;&lt;span style=&quot;color: #990000; font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;plusifyPics&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&#39; &amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Remember to set style for the div. Set your width and height to cover the area where you want to display your photo album.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;On document ready, initialize your imagePlusify and pass the options.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-align: -webkit-auto; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp;()&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-align: -webkit-auto; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; $.AjaxGet({&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-align: -webkit-auto; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; url: imgUrl,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-align: -webkit-auto; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; callback:&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;function&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-align: -webkit-auto; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $(&lt;/span&gt;&lt;span style=&quot;color: #990000; font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&#39;#plusifyPics&#39;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;).imagePlusify({&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-align: -webkit-auto; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; backgroundColor: &#39;white&#39;,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-align: -webkit-auto; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; source: data,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-align: -webkit-auto; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; displayLabel: true,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-align: -webkit-auto; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; onClick:&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp;(id, name, src) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-align: -webkit-auto; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alert(&lt;/span&gt;&lt;span style=&quot;color: #990000; font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&#39;you have clicked on album with id: [&#39;&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;+ id +&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #990000; font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&#39;] with name &quot;&#39;&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;+ name +&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #990000; font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&#39;&quot; and &#39;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #990000; font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp;&#39;it has total of &#39;&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;+ src.length +&lt;/span&gt;&lt;span style=&quot;color: #990000; font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&#39; images !!!&#39;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-align: -webkit-auto; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-align: -webkit-auto; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-align: -webkit-auto; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-align: -webkit-auto; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; });&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: #dbe5f1; text-align: -webkit-auto; text-indent: 12px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;});&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Here is the list of all the options we can set in this plugin.&lt;br /&gt;
&lt;br /&gt;
&lt;table class=&quot;infotable&quot; id=&quot;table-design&quot; style=&quot;border: 1px solid black;&quot;&gt;     &lt;thead style=&quot;background-color: silver; text-align: center;&quot;&gt;
&lt;tr&gt;&lt;th&gt;Property&lt;/th&gt;       &lt;th&gt;Values&lt;/th&gt;       &lt;th&gt;Additional Info&lt;/th&gt;      &lt;/tr&gt;
&lt;/thead&gt;      &lt;tbody&gt;
&lt;tr&gt;        &lt;td&gt;&lt;div&gt;
border&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
valid css border style&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
&#39;1px solid gray&#39; is default value&lt;/div&gt;
&lt;/td&gt;       &lt;/tr&gt;
&lt;tr&gt;        &lt;td&gt;&lt;div&gt;
borderOnMouseOver&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
valid css border style&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
&#39;1px solid black&#39; is default value&lt;/div&gt;
&lt;/td&gt;       &lt;/tr&gt;
&lt;tr&gt;        &lt;td&gt;&lt;div&gt;
padding&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
valid css padding size&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
&#39;5px&#39; is default value&lt;/div&gt;
&lt;/td&gt;       &lt;/tr&gt;
&lt;tr&gt;        &lt;td&gt;&lt;div&gt;
backgroundColor&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
valid css color&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
&amp;nbsp;&#39;#fff&#39; is default value&lt;/div&gt;
&lt;/td&gt;       &lt;/tr&gt;
&lt;tr&gt;        &lt;td&gt;&lt;div&gt;
displayLabel&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
true / false&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
by default its false&lt;/div&gt;
&lt;/td&gt;       &lt;/tr&gt;
&lt;tr&gt;        &lt;td&gt;&lt;div&gt;
labelColor&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
valid css color for the text color&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
&#39;#000&#39; is default value&lt;/div&gt;
&lt;/td&gt;       &lt;/tr&gt;
&lt;tr&gt;        &lt;td&gt;&lt;div&gt;
randomize&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
true / false&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
by default its true&lt;/div&gt;
&lt;/td&gt;       &lt;/tr&gt;
&lt;tr&gt;        &lt;td&gt;&lt;div&gt;
margin&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
margin between the image albums&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
&#39;30px&#39; is the default value&lt;/div&gt;
&lt;/td&gt;       &lt;/tr&gt;
&lt;tr&gt;        &lt;td&gt;&lt;div&gt;
width&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
album width&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
&#39;200px&#39; is the default width&lt;/div&gt;
&lt;/td&gt;       &lt;/tr&gt;
&lt;tr&gt;        &lt;td&gt;&lt;div&gt;
height&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
album height&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
&#39;200px&#39; is the default height&lt;/div&gt;
&lt;/td&gt;       &lt;/tr&gt;
&lt;tr&gt;        &lt;td&gt;&lt;div&gt;
slideBy&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
int distance by which images should slide&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
30 is the default value&lt;/div&gt;
&lt;/td&gt;       &lt;/tr&gt;
&lt;tr&gt;        &lt;td&gt;&lt;div&gt;
source&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
images, name and id as source to display image albums&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
source can be sent in 3 ways&lt;br /&gt;
1. Array of string where string is url of images&lt;br /&gt;
2. Object with id, name and array of string as members&lt;br /&gt;
3 Array of object where object has id, name and array of string as members&lt;/div&gt;
&lt;/td&gt;       &lt;/tr&gt;
&lt;tr&gt;        &lt;td&gt;&lt;div&gt;
onClick&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
Callback event raised on click of album&lt;/div&gt;
&lt;/td&gt;        &lt;td&gt;&lt;div&gt;
album id, album name and all images url as array are returned in the callback function.&lt;/div&gt;
&lt;/td&gt;       &lt;/tr&gt;
&lt;/tbody&gt;     &lt;/table&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/182468871120385105/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2012/02/jquery-google-plusify_10.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/182468871120385105'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/182468871120385105'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2012/02/jquery-google-plusify_10.html' title='jQuery Google Plusify'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-8871376220448442801</id><published>2012-01-04T01:21:00.000-05:00</published><updated>2014-05-01T16:21:22.391-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="Design Patterns"/><title type='text'>Singleton Pattern</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;u&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 12pt;&quot;&gt;Introduction&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 12pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Singleton can be defined as single instance object.&amp;nbsp;Usually singletons are used for centralized management of internal or external resources and they provide a global point of access to themselves.&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;u&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 12pt;&quot;&gt;Implementation&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 12pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Singleton has one static object which is the gateway to create the instantiate the class.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;using System;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;public class Singleton&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp; private static Singleton _instance;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp; private Singleton() {}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp; public static Singleton Instance&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (_instance == null)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _instance = new Singleton();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return _instance;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Above example has a static member, &quot;_instance&quot; of type Singleton class. This was _instance can be accessed anywhere in the application.&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Then we have private constructor of the singleton class which means that constructor can only be accessed within the same class, hence class cannot be initiated from the outside but only from inside the same class.&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;We also have readonly property called &quot;Instance&quot;&amp;nbsp;which is only entry point to the singleton class. Since _instance is static object, so once _instance object is instantiated it is for lifetime.&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Singleton Vs. Static Class&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;There are important differences between the singleton design pattern and the static keyword on classes. Static classes and singletons both provide sharing of redundant objects in memory, but they are very different in usage and implementation.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Static class example&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;You can make a static class with the static keyword. In the following example, look carefully at how the static keyword is used on the class and constructor. Static classes may be simpler, but the singleton example has many important advantages.&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 13px;&quot;&gt;Static classes and singletons both provide sharing of redundant objects in memory, but they are very different in usage and implementation.&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;center&gt; &lt;table cellpadding=&quot;1&quot; cellspacing=&quot;0&quot; style=&quot;border: solid 1px black;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;style: 25%;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&lt;b&gt;Singleton&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;td style=&quot;style: 25%;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;Static Class&lt;/span&gt;&lt;/b&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 13px; text-align: left;&quot;&gt;you can create one instance of the object and reuse it.&lt;/span&gt; &lt;/td&gt; &lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 13px; text-align: left;&quot;&gt;You cannot create the instance of static class.&lt;/span&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;min-width: 50%;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 13px;&quot;&gt;Singleton instance is created for the first time when the user requested.&lt;/span&gt; &lt;/div&gt;
&lt;/td&gt; &lt;td&gt;&lt;span style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;Static classes- are loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 13px; text-align: left;&quot;&gt;Singleton class can implement interface&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;Interface cannot be implemented on static classes&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 13px;&quot;&gt;Singleton class can have constructor.&lt;/span&gt; &lt;/div&gt;
&lt;/td&gt; &lt;td&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 13px;&quot;&gt;Static class cannot have constructor.&lt;/span&gt; &lt;/div&gt;
&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/center&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;br&gt;


Hope you enjoyed reading this post ....
&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/8871376220448442801/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2012/01/singleton-pattern.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/8871376220448442801'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/8871376220448442801'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2012/01/singleton-pattern.html' title='Singleton Pattern'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>Culver City, CA 90230, USA</georss:featurename><georss:point>33.9933257 -118.3987842</georss:point><georss:box>33.9669957 -118.4382662 34.0196557 -118.35930219999999</georss:box></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-4471307628401875058</id><published>2011-12-16T01:24:00.000-05:00</published><updated>2011-12-16T01:24:35.315-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="Design Patterns"/><title type='text'>Design Patterns</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Design Patterns are the proven solution to the common development problems faced during the software designing. These are the suggested way to solve the problems by providing cleaner, robust and efficient framework.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Design Patterns can be grouped into different categories&lt;/span&gt;&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Creational Patterns&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Structural Patterns&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Behavioral Patterns&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;Creational Patterns&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. The basic form of object creation could result in design problems or added complexity to the design. Creational design patterns solve this problem by somehow controlling this object creation. Creational design patterns are further categorized into Object-creational patterns and Class-creational patterns. Where, Object-creational patterns deal with Object creation and Class-creational deal with Class-instantiation.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;i&gt;Abstract factory pattern:&lt;/i&gt;&amp;nbsp;Creates an instance of several families of classes.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Builder pattern:&lt;/i&gt; Separates object construction from its representation.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;&lt;i&gt;Factory method pattern:&lt;/i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal;&quot;&gt;&amp;nbsp;Creates an instance of several derived classes.&lt;/span&gt;&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Lazy initialization pattern:&lt;/i&gt;&amp;nbsp;Is used as tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Prototype pattern:&lt;/i&gt;&amp;nbsp;A fully initialized instance to be copied or cloned.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;&lt;i&gt;Object pool pattern:&lt;/i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal;&quot;&gt;&amp;nbsp;Helps in avoiding expensive acquisition and release of resources by recycling objects that are no longer in use.&lt;/span&gt;&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Singleton pattern:&lt;/i&gt;&amp;nbsp;A class of which only a single instance can exist.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;Structural Patterns&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships between entities.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;i&gt;Adapter pattern:&lt;/i&gt; Match interfaces of different classes.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Bridge pattern:&lt;/i&gt; Separates an object’s interface from its implementation.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Composite pattern:&lt;/i&gt;&amp;nbsp;A tree structure of simple and composite objects.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Decorator pattern:&lt;/i&gt; Add responsibilities to objects dynamically.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Facade pattern:&lt;/i&gt; A single class that represents an entire subsystem.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Flyweight pattern:&lt;/i&gt; A fine-grained instance used for efficient sharing.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Proxy pattern:&lt;/i&gt; An object representing another object.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;b&gt;Behavioral Patterns&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;i&gt;Chain of responsibility pattern: &lt;/i&gt;A way of passing a request between a chain of objects.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Command pattern:&lt;/i&gt; Encapsulate a command request as an object.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Interpreter pattern:&lt;/i&gt; A way to include language elements in a program.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Iterator pattern:&lt;/i&gt; Sequentially access the elements of a collection.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Mediator pattern:&lt;/i&gt; Defines simplified communication between classes.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Memento pattern:&lt;/i&gt;&amp;nbsp;Capture and restore an object&#39;s internal state.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Observer pattern:&lt;/i&gt; A way of notifying change to a number of classes.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;State pattern:&lt;/i&gt; Alter an object&#39;s behavior when its state changes.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Strategy pattern:&lt;/i&gt; Encapsulates an algorithm inside a class.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Template method pattern:&lt;/i&gt; Defer the exact steps of an algorithm to a subclass.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Visitor pattern:&lt;/i&gt; Defines a new operation to a class without change.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/4471307628401875058/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2011/12/design-patterns.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/4471307628401875058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/4471307628401875058'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2011/12/design-patterns.html' title='Design Patterns'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-6323776316353569869</id><published>2011-12-12T16:03:00.001-05:00</published><updated>2011-12-15T23:16:41.872-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="GZIP"/><category scheme="http://www.blogger.com/atom/ns#" term="HTML"/><title type='text'>GZIP compression for better performance</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Compression is easy and effective way to reduce the bandwidth to download data from internet and increase the performance of the web site. In other words, server sends the compressed HTML in the form of zip file to the client and the client browser unzips the file to&amp;nbsp;retrieve&amp;nbsp;the HTML. All the latest browsers support gzip/deflate.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;Why we need it?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Lets understand how the web model works. When we visit the web page e.g.&amp;nbsp;&lt;a href=&quot;http://jassra.com/&quot;&gt;http://jassra.com/&lt;/a&gt;, basically we are requesting for Index file from the server and server returns the same file to the client.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://3.bp.blogspot.com/-V3mjoe8y23I/TuhIf-irPeI/AAAAAAAAA_c/EB6-Nz1Ho6o/s1600/request_response_without_gzip.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;210&quot; src=&quot;http://3.bp.blogspot.com/-V3mjoe8y23I/TuhIf-irPeI/AAAAAAAAA_c/EB6-Nz1Ho6o/s400/request_response_without_gzip.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;The way communication takes place between the client and the server is described below:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Browser requests a file from the server and the data sent for the request is 100 B&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Server finds the requested file&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Creates HTML for the response&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Server sends 1.9 KB of data back to the browser. And&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;user needs to wait for the data to be downloaded and finally browser displays the page&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Network trace&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://3.bp.blogspot.com/-pQFbqjGKbNQ/Tub0AppP-qI/AAAAAAAAA-s/afqb6B0hwTo/s1600/jassra.com_before_gzip.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;300&quot; src=&quot;http://3.bp.blogspot.com/-pQFbqjGKbNQ/Tub0AppP-qI/AAAAAAAAA-s/afqb6B0hwTo/s320/jassra.com_before_gzip.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Now with gzip if we can compress the file to reduce the size of the file and less data needs to be transferred to the client resulting in less bandwidth and quick response.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://2.bp.blogspot.com/-fYwHZvRYzWI/TuhIoebTQXI/AAAAAAAAA_k/Kg4_3fBG9qY/s1600/request_response_with_gzip.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;210&quot; src=&quot;http://2.bp.blogspot.com/-fYwHZvRYzWI/TuhIoebTQXI/AAAAAAAAA_k/Kg4_3fBG9qY/s400/request_response_with_gzip.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Browser requests a file from server. Data sent for the request is 100 B&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Server finds the requested file&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Creates HTML for the response and &amp;nbsp;zips the file&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Server sends 874 B of data back to the browser. 874 B of data is downloaded quickly as compared to the uncompressed data and browser displays the page much faster&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Means Happy Customer..... :o)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Network trace&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://2.bp.blogspot.com/-3Cgz5C0OmV8/TuhHOlkaUUI/AAAAAAAAA_U/_9wn4ovFwCE/s1600/jassra.com_after_gzip.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;314&quot; src=&quot;http://2.bp.blogspot.com/-3Cgz5C0OmV8/TuhHOlkaUUI/AAAAAAAAA_U/_9wn4ovFwCE/s320/jassra.com_after_gzip.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;For more understanding about how gzip algorithm works, please view this video.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;object class=&quot;BLOGGER-youtube-video&quot; classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot; codebase=&quot;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0&quot; data-thumbnail-src=&quot;http://0.gvt0.com/vi/Mjab_aZsdxw/0.jpg&quot; height=&quot;266&quot; width=&quot;320&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://www.youtube.com/v/Mjab_aZsdxw&amp;fs=1&amp;source=uds&quot; /&gt;

&lt;param name=&quot;bgcolor&quot; value=&quot;#FFFFFF&quot; /&gt;

&lt;embed width=&quot;320&quot; height=&quot;266&quot;  src=&quot;http://www.youtube.com/v/Mjab_aZsdxw&amp;fs=1&amp;source=uds&quot; type=&quot;application/x-shockwave-flash&quot;&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Please feel free to leave your feedback ....&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/6323776316353569869/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2011/12/gzip-compression-for-better-performance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/6323776316353569869'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/6323776316353569869'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2011/12/gzip-compression-for-better-performance.html' title='GZIP compression for better performance'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-V3mjoe8y23I/TuhIf-irPeI/AAAAAAAAA_c/EB6-Nz1Ho6o/s72-c/request_response_without_gzip.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7812923111809291334.post-5831178200541191999</id><published>2011-12-11T13:08:00.001-05:00</published><updated>2011-12-11T23:24:54.513-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="HTML"/><category scheme="http://www.blogger.com/atom/ns#" term="HTML5"/><category scheme="http://www.blogger.com/atom/ns#" term="LocalStorage"/><category scheme="http://www.blogger.com/atom/ns#" term="SessionStorage"/><category scheme="http://www.blogger.com/atom/ns#" term="WebStorage"/><title type='text'>Web Storage in HTML (5)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;In newer version of HTML (so called HTML 5), we have two new mechanisms introduced to store structured data related to session cookies and cookies.&lt;/span&gt;&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Session Storage (sessionStorage)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Local Storage (localStorage)&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;As the name specifies, local storage is for the long term &amp;nbsp;and session storage is only limited to that particular session.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;Session Storage&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Session storage allows to save data on the client side persisting for that particular session only. Data can be saved on the client side and shared between multiple pages during that session but once session is closed, all the stored data on the client side is deleted and is never accessible again. This also helps in differentiating the two different windows of the same site opened on the same machine and maintaining their instance without being affected with the activities on the other window. So i would think its right to say that session storage is dependent on combination of session id and site id together.&lt;/span&gt;&lt;br /&gt;
&lt;b style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red; font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;i&gt;Note : The lifetime of a browsing context can be unrelated to the lifetime of the actual user agent process itself, as the user agent may support resuming sessions after a restart.&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Local Storage&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Local storage allows to save data on the client side for the longer duration for the returning users. Local storage data is save on the client side and is only dependent on site id. With local storage, changes made on the one site window will affect on the other window opened on the same machine.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;The API&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b style=&quot;font-family: sans-serif;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;Web storage provide list to key/value pair called items.Keys are strings. Any string (including the empty string) is a valid key. Values are similarly strings.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;&lt;i&gt;Adding Item &amp;nbsp;- Insert new item in the storage&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;sessionStorage.setItem(key, value)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;localStorage.setItem(key, value)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;&lt;i&gt;Retrieving Item - Retrieve item from the storage&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;sessionStorage.getItem(key)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;localStorage.getItem(key)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;&lt;i&gt;Removing Item - Removes item for the storage&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;sessionStorage.removeItem(key)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;localStorage.removeItem(key)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;&lt;i&gt;Clear - Removes all the items for the storage&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;sessionStorage.clear()&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;localStorage.clear()&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;&lt;i&gt;Length - Get the count of items in the storage&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;sessionStorage.length&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;localStorage.length&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: sans-serif; font-weight: bold;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b style=&quot;font-family: sans-serif;&quot;&gt;Code Example&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;To check whether local or session storage is supported&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: #dbe5f1; background-image: initial; background-origin: initial; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto; text-indent: 9pt;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: darkgreen; font-family: Consolas; font-size: 13px;&quot;&gt;// Check for the browser supports session storage&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: #dbe5f1; background-image: initial; background-origin: initial; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto; text-indent: 9pt;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 12px;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #dddddd; font-family: Consolas; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;sessionStorage&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;window &amp;amp;&amp;amp; window[&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;sessionStorage&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;] !=&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: #dbe5f1; background-image: initial; background-origin: initial; color: #dddddd; font-family: &#39;Segoe UI&#39;, Arial, Helvetica, sans-serif; font-size: 12px; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto; text-indent: 9pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen; font-size: 10pt;&quot;&gt;// Session storage supported&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: #dbe5f1; background-image: initial; background-origin: initial; color: #dddddd; font-family: &#39;Segoe UI&#39;, Arial, Helvetica, sans-serif; font-size: 12px; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto; text-indent: 9pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: black; font-size: 10pt;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: #dbe5f1; background-image: initial; background-origin: initial; color: #dddddd; font-family: &#39;Segoe UI&#39;, Arial, Helvetica, sans-serif; font-size: 12px; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto; text-indent: 9pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: black; font-size: 10pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: #dbe5f1; background-image: initial; background-origin: initial; color: #dddddd; font-family: &#39;Segoe UI&#39;, Arial, Helvetica, sans-serif; font-size: 12px; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto; text-indent: 9pt;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: darkgreen; font-family: Consolas; font-size: 13px;&quot;&gt;// Check for the browser supports local storage&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; color: black; font-family: &#39;Times New Roman&#39;; font-size: medium; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: left; text-indent: 9pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;localStorage&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;window &amp;amp;&amp;amp; window[&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;localStorage&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;] !=&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; color: black; font-family: &#39;Times New Roman&#39;; font-size: medium; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: left; text-indent: 9pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen; font-size: 10pt;&quot;&gt;// Local storage supported&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; color: black; font-family: &#39;Times New Roman&#39;; font-size: medium; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: left; text-indent: 9pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: black; font-size: 10pt;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: black; font-size: 10pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: #dbe5f1; background-image: initial; background-origin: initial; color: #dddddd; font-family: &#39;Segoe UI&#39;, Arial, Helvetica, sans-serif; font-size: 12px; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto; text-indent: 9pt;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-indent: 9pt;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: #dbe5f1; background-image: initial; background-origin: initial; color: #dddddd; font-family: &#39;Segoe UI&#39;, Arial, Helvetica, sans-serif; font-size: 12px; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto; text-indent: 9pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: darkgreen; font-size: 10pt;&quot;&gt;// Write to session storage&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: #dbe5f1; background-image: initial; background-origin: initial; color: #dddddd; font-family: &#39;Segoe UI&#39;, Arial, Helvetica, sans-serif; font-size: 12px; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto; text-indent: 9pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;sessionStorage.setItem(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;language&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;en-us&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: #dbe5f1; background-image: initial; background-origin: initial; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto; text-indent: 9pt;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: darkgreen; font-family: Consolas; font-size: 13px;&quot;&gt;// Read from&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: darkgreen; font-family: Consolas; font-size: 13px;&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: darkgreen; font-family: Consolas; font-size: 13px;&quot;&gt;&amp;nbsp;storage&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: #dbe5f1; background-image: initial; background-origin: initial; color: #dddddd; font-family: &#39;Segoe UI&#39;, Arial, Helvetica, sans-serif; font-size: 12px; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto; text-indent: 9pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;var&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;sessValLang&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: Consolas; font-size: 13px;&quot;&gt;session&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Storage.getItem(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;language&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: #dbe5f1; background-image: initial; background-origin: initial; color: #dddddd; font-family: &#39;Segoe UI&#39;, Arial, Helvetica, sans-serif; font-size: 12px; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto; text-indent: 9pt;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: darkgreen; font-family: Consolas; font-size: 13px;&quot;&gt;// Removing session storage item&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: #dbe5f1; background-image: initial; background-origin: initial; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto; text-indent: 9pt;&quot;&gt;
&lt;div style=&quot;color: #dddddd; font-family: &#39;Segoe UI&#39;, Arial, Helvetica, sans-serif; font-size: 12px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: Consolas; font-size: 13px;&quot;&gt;session&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Storage.removeItem(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: maroon; font-family: Consolas; font-size: 13px;&quot;&gt;&quot;language&quot;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: Consolas; font-size: 13px;&quot;&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #dddddd; font-family: &#39;Segoe UI&#39;, Arial, Helvetica, sans-serif; font-size: 12px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: Consolas; font-size: 13px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #dddddd; font-family: &#39;Segoe UI&#39;, Arial, Helvetica, sans-serif; font-size: 12px;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; color: black; font-family: &#39;Times New Roman&#39;; font-size: medium; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: left; text-indent: 9pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: darkgreen; font-size: 10pt;&quot;&gt;// Write to local storage&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; color: black; font-family: &#39;Times New Roman&#39;; font-size: medium; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: left; text-indent: 9pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;localStorage.setItem(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;language&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;en-us&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; color: black; font-family: &#39;Times New Roman&#39;; font-size: medium; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: left; text-indent: 9pt;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: darkgreen; font-family: Consolas; font-size: 13px;&quot;&gt;// Read from local storage&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; color: black; font-family: &#39;Times New Roman&#39;; font-size: medium; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: left; text-indent: 9pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;var&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;locValLang= localStorage.getItem(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;language&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; color: black; font-family: &#39;Times New Roman&#39;; font-size: medium; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: left; text-indent: 9pt;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; color: black; font-family: &#39;Times New Roman&#39;; font-size: medium; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: left; text-indent: 9pt;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: darkgreen; font-family: Consolas; font-size: 13px;&quot;&gt;// Removing local storage item&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; color: black; font-family: &#39;Times New Roman&#39;; font-size: medium; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: left; text-indent: 9pt;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: Consolas; font-size: 13px;&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Storage.removeItem(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: maroon; font-family: Consolas; font-size: 13px;&quot;&gt;&quot;language&quot;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: Consolas; font-size: 13px;&quot;&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: black; font-family: &#39;Times New Roman&#39;; font-size: medium; text-align: left; text-indent: 0px;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: #dbe5f1; background-image: initial; background-origin: initial; color: #dddddd; font-family: &#39;Segoe UI&#39;, Arial, Helvetica, sans-serif; font-size: 12px; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: -webkit-auto; text-indent: 9pt;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; margin-bottom: 0pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-indent: 9pt;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: darkgreen; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;a href=&quot;http://jassra.com/Demos/Html5/WebStorage&quot; style=&quot;font-family: sans-serif;&quot; target=&quot;_blank&quot;&gt;Click here&lt;/a&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt; for the demo ...&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif;&quot;&gt;P.S. This is my first post, please feel free to guide me or correct me for betterment ... Thanks in advance.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://avijassra.blogspot.com/feeds/5831178200541191999/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://avijassra.blogspot.com/2011/12/web-storage-in-html-5.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/5831178200541191999'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7812923111809291334/posts/default/5831178200541191999'/><link rel='alternate' type='text/html' href='http://avijassra.blogspot.com/2011/12/web-storage-in-html-5.html' title='Web Storage in HTML (5)'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12949480703901042443</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>