<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;Dk8GR307eCp7ImA9WhVTFE0.&quot;"><id>tag:blogger.com,1999:blog-321913728519024524</id><updated>2012-02-27T20:53:46.300-08:00</updated><category term="LINQ" /><category term="Neural Network" /><category term="Performance" /><category term="Feed Forward" /><category term="3-tier" /><category term="Windows" /><category term="Apple" /><category term="Software Architecture" /><category term="Google" /><category term="ASP.NET" /><category term="C#" /><category term="mvc" /><category term="Artificial Intelligence" /><category term="JQuery" /><category term="n-tier" /><category term="Apps" /><category term="Back Propagation" /><category term="Linux" /><category term="Software" /><category term="LINQ Perfomance" /><category term="Coding Practices" /><category term="Frogswell.com" /><category term="Applications" /><category term="Optimization" /><category term=".NET" /><title>All Things CS</title><subtitle type="html">All Things Related to CS (C# or Computer Science)</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://allthingscs.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://allthingscs.blogspot.com/" /><author><name>bh</name><uri>http://www.blogger.com/profile/02885141522169238049</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://2.bp.blogspot.com/-XTV5rmRh8TA/TXLmwmOXtgI/AAAAAAAAABo/gKL0C70swj0/s220/CleanedUpBryan3.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/AllThingsCs" /><feedburner:info uri="allthingscs" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;Dk8GR306eCp7ImA9WhVTFE0.&quot;"><id>tag:blogger.com,1999:blog-321913728519024524.post-5039266903869708217</id><published>2012-02-27T20:53:00.000-08:00</published><updated>2012-02-27T20:53:46.310-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-27T20:53:46.310-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Apps" /><category scheme="http://www.blogger.com/atom/ns#" term="Applications" /><category scheme="http://www.blogger.com/atom/ns#" term="Linux" /><category scheme="http://www.blogger.com/atom/ns#" term="Windows" /><category scheme="http://www.blogger.com/atom/ns#" term="Software" /><category scheme="http://www.blogger.com/atom/ns#" term="Google" /><category scheme="http://www.blogger.com/atom/ns#" term="Apple" /><category scheme="http://www.blogger.com/atom/ns#" term="Frogswell.com" /><title>Frogswell.com</title><content type="html">Although not directly related to my other postings. This is a plug for &lt;a href="http://www.frogswell.com" target="_blank"&gt;Frogswell.com&lt;/a&gt;. Of course I am helping with Frogswell.com.
&lt;br/&gt;
&lt;br/&gt;
&lt;a href="http://www.frogswell.com" target="_blank"&gt;Frogswell.com&lt;/a&gt; is to reaching out right now to developers and end-users of applications across all platforms to learn how they can better communicate with each other. Or in-other-words, if a developer has written some software, and a user is looking for that software, we'd like to happily bring these two together. Bridging the gap between the developer and the end-user. Likewise, we also hope such an interaction will provide a natural forum for the user to communicate to developers what they want to see in their software.
&lt;br/&gt;
&lt;br/&gt;
There are a couple of surveys available on the site. The intent of the surveys is to better understand on our part how we might successfully build this bridge.
&lt;br/&gt;
&lt;br/&gt;
Please note, the surveys are intentionally vague at this point so as to get an unbiased first impression.
&lt;br/&gt;
&lt;br/&gt;
Thanks in advance!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/321913728519024524-5039266903869708217?l=allthingscs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/L3KQqRR_ZuVFN96FNf1fTTeFDLg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/L3KQqRR_ZuVFN96FNf1fTTeFDLg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/L3KQqRR_ZuVFN96FNf1fTTeFDLg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/L3KQqRR_ZuVFN96FNf1fTTeFDLg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/AllThingsCs/~4/es74oXkbajg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allthingscs.blogspot.com/feeds/5039266903869708217/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allthingscs.blogspot.com/2012/02/frogswellcom.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/5039266903869708217?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/5039266903869708217?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/AllThingsCs/~3/es74oXkbajg/frogswellcom.html" title="Frogswell.com" /><author><name>bh</name><uri>http://www.blogger.com/profile/02885141522169238049</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://2.bp.blogspot.com/-XTV5rmRh8TA/TXLmwmOXtgI/AAAAAAAAABo/gKL0C70swj0/s220/CleanedUpBryan3.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://allthingscs.blogspot.com/2012/02/frogswellcom.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0YMRnY-fSp7ImA9WhZRGUo.&quot;"><id>tag:blogger.com,1999:blog-321913728519024524.post-6617944515322961762</id><published>2011-04-16T10:31:00.000-07:00</published><updated>2011-04-16T10:33:07.855-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-16T10:33:07.855-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Neural Network" /><category scheme="http://www.blogger.com/atom/ns#" term="Feed Forward" /><category scheme="http://www.blogger.com/atom/ns#" term="Artificial Intelligence" /><category scheme="http://www.blogger.com/atom/ns#" term="Back Propagation" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>Neural Networks with C# - part 2</title><content type="html">&lt;a style="font-size:10px;" href="https://sites.google.com/site/allthingscs/NN.zip?attredirects=0&amp;d=1"&gt;Download Sample&lt;/a&gt;
&lt;h4&gt;A High Level Understanding of Backpropagation Learning&lt;/h4&gt;
&lt;a href="http://www.learnartificialneuralnetworks.com/backpropagation.html"&gt;Backpropagation&lt;/a&gt; is a technique used to help a &lt;a href="http://www.heatonresearch.com/articles/5/page2.html"&gt;feedforward neural networks&lt;/a&gt; learn or improve the accuracy of it's output based on the expected output of the learning sample set. That is to say, we will have a set of sample inputs with their expected outputs and then use that set to make adjustments in for the weights of our neuron associations (again I like to call them axons). This approach effectively solves the problem of how to update hidden layers.
&lt;br/&gt;&lt;br/&gt;
&lt;h4&gt;The Math Basics for Backpropagation Learning&lt;/h4&gt;
&lt;a href="http://1.bp.blogspot.com/-9c5oCJNcNkY/TanJ7kFjc5I/AAAAAAAAACw/r43Snd1U944/s1600/NeuralNetwork_BackpropagationFunctions.jpg"&gt;&lt;img border="0" height="130" width="320" src="http://1.bp.blogspot.com/-9c5oCJNcNkY/TanJ7kFjc5I/AAAAAAAAACw/r43Snd1U944/s320/NeuralNetwork_BackpropagationFunctions.jpg" /&gt;&lt;/a&gt;
&lt;br/&gt;
&lt;a style="font-size:10px" href="http://www.youtube.com/watch?v=nz3NYD73H6E&amp;p=3EA65335EAC29EE8"&gt;http://www.youtube.com/watch?v=nz3NYD73H6E&amp;p=3EA65335EAC29EE8&lt;/a&gt;
&lt;br/&gt;
&lt;ol&gt;
&lt;li&gt;&lt;i&gt;r&lt;/i&gt;&lt;span style="font-size: 9px"&gt;i&lt;/span&gt; is the error for the &lt;i&gt;n&lt;/i&gt;th node of the &lt;i&gt;i&lt;/i&gt;th layer. Furthermore, &lt;i&gt;r&lt;/i&gt; is &lt;strong&gt;only&lt;/strong&gt; for the output layer; it is simply the difference between the expected output and the output (see Neuron.CalcDelta() in &lt;a href="https://sites.google.com/site/allthingscs/NN.zip?attredirects=0&amp;d=1"&gt;example download&lt;/a&gt;). &lt;i&gt;v&lt;/i&gt;&lt;span style="font-size: 9px"&gt;i&lt;/span&gt; is the values calculated during the normal feedforward algorithms (see &lt;a href="http://allthingscs.blogspot.com/2011/04/neural-networks-with-c-part-1.html"&gt;part 1&lt;/a&gt;). &lt;i&gt;&amp;Phi;&lt;/i&gt;' will be explained in equation 4. &lt;i&gt;&amp;delta;&lt;/i&gt;&lt;span style="font-size: 9px"&gt;i&lt;/span&gt; is the calculated change for neuron &lt;i&gt;n&lt;/i&gt; within the &lt;i&gt;i&lt;/i&gt;th layer.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Critical:&lt;/strong&gt; This is much like equation 1 with some very distinct differences. You may notice that instead of using &lt;i&gt;r&lt;/i&gt;, the error is calculated by the sum of the &lt;i&gt;j&lt;/i&gt;th delta with the weighted association axons of the &lt;i&gt;n&lt;/i&gt;th neuron with the &lt;i&gt;j&lt;/i&gt;th layer.&lt;/li&gt;
&lt;li&gt;This equation is the gradient or calculated change of weights. Or in other words, this is where we make the learned changes. &lt;i&gt;&amp;eta;&lt;/i&gt; is simply a learning rate between 0 and 1. &lt;i&gt;y&lt;/i&gt; is the original input values calculated from the axon for the &lt;i&gt;n&lt;/i&gt;th neuron during the feedforward calculation.&lt;/li&gt;
&lt;li&gt;This is the inverse or derivative activation function for either sigmoid or hyperbolic tangent functions (depends on whichever activation function was used for the neurons).&lt;/li&gt;
&lt;/ol&gt;
As mentioned in part 1, &lt;i&gt;n&lt;/i&gt; is referring to the &lt;i&gt;n&lt;/i&gt;th node in a series of node calculations from input to output. Also, &lt;i&gt;i&lt;/i&gt; and &lt;i&gt;j&lt;/i&gt; simply note the distinction between one layer and another.
&lt;br/&gt;&lt;br/&gt;
&lt;a href="http://allthingscs.blogspot.com/2011/04/neural-networks-with-c-part-1.html"&gt;&amp;lt;&amp;lt; back to part 1&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;a style="font-size:10px;" href="https://sites.google.com/site/allthingscs/NN.zip?attredirects=0&amp;d=1"&gt;Download Sample&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/321913728519024524-6617944515322961762?l=allthingscs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/VyBqR99pjed4VxWMNSMzJLnrUdY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VyBqR99pjed4VxWMNSMzJLnrUdY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/VyBqR99pjed4VxWMNSMzJLnrUdY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VyBqR99pjed4VxWMNSMzJLnrUdY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/AllThingsCs/~4/b1bofEEwOIs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allthingscs.blogspot.com/feeds/6617944515322961762/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allthingscs.blogspot.com/2011/04/neural-networks-with-c-part-2.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/6617944515322961762?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/6617944515322961762?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/AllThingsCs/~3/b1bofEEwOIs/neural-networks-with-c-part-2.html" title="Neural Networks with C# - part 2" /><author><name>bh</name><uri>http://www.blogger.com/profile/02885141522169238049</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://2.bp.blogspot.com/-XTV5rmRh8TA/TXLmwmOXtgI/AAAAAAAAABo/gKL0C70swj0/s220/CleanedUpBryan3.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-9c5oCJNcNkY/TanJ7kFjc5I/AAAAAAAAACw/r43Snd1U944/s72-c/NeuralNetwork_BackpropagationFunctions.jpg" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://allthingscs.blogspot.com/2011/04/neural-networks-with-c-part-2.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0UNRn86fSp7ImA9WhZRGUo.&quot;"><id>tag:blogger.com,1999:blog-321913728519024524.post-354015622976978091</id><published>2011-04-14T20:22:00.000-07:00</published><updated>2011-04-16T10:34:57.115-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-16T10:34:57.115-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Neural Network" /><category scheme="http://www.blogger.com/atom/ns#" term="Feed Forward" /><category scheme="http://www.blogger.com/atom/ns#" term="Artificial Intelligence" /><category scheme="http://www.blogger.com/atom/ns#" term="Back Propagation" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>Neural Networks with C# - part 1</title><content type="html">&lt;a style="font-size:10px;" href="https://sites.google.com/site/allthingscs/NN.zip?attredirects=0&amp;d=1"&gt;Download Sample&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;a href="http://en.wikipedia.org/wiki/Neural_network"&gt;Neural networks&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Artificial_intelligence"&gt;artificial intelligence&lt;/a&gt; is a fairly large topic. As such I will limit this article to a direct and &lt;a href="https://sites.google.com/site/allthingscs/NN.zip?attredirects=0&amp;d=1"&gt;simple example&lt;/a&gt; of creating a neural network with C#. Of course there are many other &lt;a href="http://www.codeproject.com/KB/recipes/aforge_neuro.aspx"&gt;good examples&lt;/a&gt;, however I hope to provide simple code for those who are attempting to learn about neural networks. This example uses a standard hidden layer &lt;a href="http://en.wikipedia.org/wiki/Feedforward_neural_network"&gt;feedforward&lt;/a&gt; with &lt;a href="http://en.wikipedia.org/wiki/Backpropagation"&gt;backpropagation learning algorithm&lt;/a&gt; type of network.
&lt;br/&gt;&lt;br/&gt;
&lt;h4&gt;A High Level Understanding&lt;/h4&gt;
The type of neural network discussed in this article is one that has an input layer, one or more hidden layers, and an output layer. Below are two examples of potential neural networks.
&lt;br/&gt;&lt;br/&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://1.bp.blogspot.com/-PDXRTIVGrEE/TaZoPDC827I/AAAAAAAAACI/4bdDSl8es20/s1600/NeuralNetwork_A.jpg"&gt;&lt;img border="0" height="236" width="320" src="http://1.bp.blogspot.com/-PDXRTIVGrEE/TaZoPDC827I/AAAAAAAAACI/4bdDSl8es20/s1600/NeuralNetwork_A.jpg" /&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://2.bp.blogspot.com/-3LmXgQ6xSt0/TaZpU4Va7nI/AAAAAAAAACQ/1Rp4IkKLybA/s1600/NeuralNetwork_B.jpg"&gt;&lt;img border="0" height="236" width="320" src="http://2.bp.blogspot.com/-3LmXgQ6xSt0/TaZpU4Va7nI/AAAAAAAAACQ/1Rp4IkKLybA/s320/NeuralNetwork_B.jpg" /&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
Because of the obvious correlation between the cognitive thought process of the brain and an attempt to create a mathematical simulated model of it (thanks to &lt;a href="http://library.thinkquest.org/C007395/tqweb/history.html"&gt;John Von Neumann&lt;/a&gt;), like the term &lt;i&gt;neural&lt;/i&gt; in neural networks, each node in the network is likewise called a neuron. The associate links between nodes I like to call axons (not officially called that, but I like it since it keeps with the whole biological brain naming conventions).
&lt;br/&gt;&lt;br/&gt;
&lt;h4&gt;The Math Basics of a Feedforward Network&lt;/h4&gt;


&lt;a href="http://1.bp.blogspot.com/-LWtGYVhq2b8/TaewVFcPhBI/AAAAAAAAACo/mBvGOh3GfqA/s1600/NeuralNetwork_FeedforwardFunctions.jpg"&gt;&lt;img border="0" height="247" width="320" src="http://1.bp.blogspot.com/-LWtGYVhq2b8/TaewVFcPhBI/AAAAAAAAACo/mBvGOh3GfqA/s320/NeuralNetwork_FeedforwardFunctions.jpg" /&gt;&lt;/a&gt;


&lt;br/&gt;
&lt;a style="font-size:10px" href="http://www.youtube.com/watch?v=nz3NYD73H6E&amp;p=3EA65335EAC29EE8"&gt;http://www.youtube.com/watch?v=nz3NYD73H6E&amp;p=3EA65335EAC29EE8&lt;/a&gt;
&lt;br/&gt;
&lt;ol&gt;
&lt;li&gt;&lt;i&gt;v&lt;/i&gt;&lt;span style="font-size: 9px"&gt;j&lt;/span&gt; is the input values for the &lt;i&gt;j&lt;/i&gt;th layer. &lt;i&gt;w&lt;/i&gt;&lt;span style="font-size: 9px"&gt;ji&lt;/span&gt; is the axon connectors 0 thru &lt;i&gt;m&lt;/i&gt; from the &lt;i&gt;i&lt;/i&gt;th layer to the &lt;i&gt;j&lt;/i&gt;th layer.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;y&lt;/i&gt; is the input values for the &lt;i&gt;j&lt;/i&gt;th layer. This is calculated by passing the calculated value of node &lt;i&gt;n&lt;/i&gt; coming from the &lt;i&gt;i&lt;/i&gt;th layer to the activation function &lt;i&gt;&amp;Phi;(x)&lt;/i&gt;.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;&amp;Phi;(x)&lt;/i&gt; is the activation function using either a sigmoid function or a hyperbolic tangent function (I prefer &lt;i&gt;tanh&lt;/i&gt; because it better handles negative values).&lt;/li&gt;
&lt;/ol&gt;
It should further be noted that &lt;i&gt;n&lt;/i&gt; is referring to the &lt;i&gt;n&lt;/i&gt;th node in a series of node calculations from input to output. Also, &lt;i&gt;i&lt;/i&gt; and &lt;i&gt;j&lt;/i&gt; simply note the distinction between one layer and another.
&lt;br/&gt;&lt;br/&gt;
I highly recommend watching &lt;a href="http://www.youtube.com/view_play_list?p=3EA65335EAC29EE8"&gt;Prof. S. Sengupta lectures&lt;/a&gt; for deriving these equations.

&lt;br/&gt;
&lt;br/&gt;
&lt;a href="http://allthingscs.blogspot.com/2011/04/neural-networks-with-c-part-2.html"&gt;See part 2 &amp;gt;&amp;gt;&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;a style="font-size:10px;" href="https://sites.google.com/site/allthingscs/NN.zip?attredirects=0&amp;d=1"&gt;Download Sample&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/321913728519024524-354015622976978091?l=allthingscs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/4ecrushAWoQzWe9PSJL7EYZT-gs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4ecrushAWoQzWe9PSJL7EYZT-gs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/4ecrushAWoQzWe9PSJL7EYZT-gs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4ecrushAWoQzWe9PSJL7EYZT-gs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/AllThingsCs/~4/ACg8upi-wG4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allthingscs.blogspot.com/feeds/354015622976978091/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allthingscs.blogspot.com/2011/04/neural-networks-with-c-part-1.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/354015622976978091?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/354015622976978091?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/AllThingsCs/~3/ACg8upi-wG4/neural-networks-with-c-part-1.html" title="Neural Networks with C# - part 1" /><author><name>bh</name><uri>http://www.blogger.com/profile/02885141522169238049</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://2.bp.blogspot.com/-XTV5rmRh8TA/TXLmwmOXtgI/AAAAAAAAABo/gKL0C70swj0/s220/CleanedUpBryan3.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-PDXRTIVGrEE/TaZoPDC827I/AAAAAAAAACI/4bdDSl8es20/s72-c/NeuralNetwork_A.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://allthingscs.blogspot.com/2011/04/neural-networks-with-c-part-1.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEAGR3o9fCp7ImA9Wx9aGUo.&quot;"><id>tag:blogger.com,1999:blog-321913728519024524.post-723737220041674997</id><published>2011-03-12T16:38:00.000-08:00</published><updated>2011-03-12T16:38:46.464-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-12T16:38:46.464-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Software Architecture" /><title>Documenting Software Architectural Requirements</title><content type="html">&lt;a href="https://sites.google.com/site/allthingscs/GUISearchArchitecturalDocument.doc?attredirects=0"&gt;Download Example&lt;/a&gt;
&lt;br /&gt;
&lt;h4&gt;Background&lt;/h4&gt;
Gathering requirements for a software project can definitely be challenging. Maintenance projects for familiar products are usually easier than starting a project for a new product. After searching through many books, articles, and gaining some practical experience, I have thus far developed a direct and simple method of documenting architectural requirements.
&lt;br/&gt;&lt;br/&gt;
&lt;div style="border: 1px solid #eee; background-color: #ffffee;padding: 20px; color: gray;"&gt;
&lt;i style="font-size: 11px"&gt;&lt;strong&gt;Note:&lt;/strong&gt; Hands down the best article I have read is written by &lt;a href="http://www.ibm.com/developerworks/rational/library/4706.html#author1"&gt;Peter Eeles&lt;/a&gt; at &lt;a href="http://www.ibm.com"&gt;IBM&lt;/a&gt;. His article can be found at &lt;a href="http://www.ibm.com/developerworks/rational/library/4706.html#iratings"&gt;http://www.ibm.com/developerworks/rational/library/4706.html#iratings&lt;/a&gt;.

Ultimately Eeles' process is a &lt;i&gt;quality attributes&lt;/i&gt; type of approach to gathering requirements (see some of the links below).
&lt;ul style="font-size: 10px;"&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Non-functional_requirement"&gt;http://en.wikipedia.org/wiki/Non-functional_requirement&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.softwarearchitectures.com/go/Discipline/DesigningArchitecture/QualityAttributes/tabid/64/Default.aspx"&gt;http://www.softwarearchitectures.com/go/Discipline/DesigningArchitecture/QualityAttributes/tabid/64/Default.aspx&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.softwaretestinghelp.com/what-are-the-quality-attributes/"&gt;http://www.softwaretestinghelp.com/what-are-the-quality-attributes/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/i&gt;
&lt;/div&gt;
&lt;br /&gt;
Whether or not you use Eeles' approach for gathering requirements, I believe this method for documentation is fairly flexible and natural; especially for those using quality attributes.
&lt;br /&gt;&lt;br/&gt;
&lt;h4&gt;Format&lt;/h4&gt;
You will notice in the &lt;a href="https://sites.google.com/site/allthingscs/GUISearchArchitecturalDocument.doc?attredirects=0"&gt;downloadable example&lt;/a&gt; that each requirement takes on the templated form of:
&lt;br/&gt;
&lt;br/&gt;
&lt;div style="border: 1px solid gray; padding: 20px;"&gt;
1. &lt;strong&gt;Statement:&lt;/strong&gt;
&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a. Question [optional]:
&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;b. Answer [optional]:
&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;c. &lt;strong&gt;Quality Attributes:&lt;/strong&gt;
&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;d. &lt;strong&gt;Architectural Realization:&lt;/strong&gt;
&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;e. &lt;strong&gt;Goal Metrics&lt;/strong&gt; [optional]&lt;strong&gt;:&lt;/strong&gt;
&lt;/div&gt;&lt;br/&gt;
&lt;h4&gt;Explanation&lt;/h4&gt;
What exactly is this the formatted structure about? Let's go over each line.
&lt;br/&gt;&lt;br/&gt;
&lt;i&gt;&lt;u&gt;Statement:&lt;/u&gt;&lt;/i&gt;
The statement is intended to be just that, a statement. Generally when discussions occur about what the application should or shouldn't do, statements by various stakeholders are made. Those statements should then be documented, hence the rest of the format is derived from the statement. Of course, all statements should be reviewed, revised, and approved by all key stakeholders. It is then up to the software architect to make sure that all statements will make sense technically.
&lt;br/&gt;&lt;br/&gt;
&lt;i&gt;&lt;u&gt;Questions &amp;amp; Answers:&lt;/u&gt;&lt;/i&gt;
Although these are optional, they may be helpful to facilitate clarification or future discussion. It should be noted that we may not necessarily be limited to one question and one answer. Feel free to add as many as necessary.
&lt;br/&gt;&lt;br/&gt;
&lt;i&gt;&lt;u&gt;Quality Attributes:&lt;/u&gt;&lt;/i&gt;
Which set of quality attributes we use and why we use them is beyond the discussion of this article (I used Eeles' in my &lt;a href="https://sites.google.com/site/allthingscs/GUISearchArchitecturalDocument.doc?attredirects=0"&gt;example download&lt;/a&gt;).
&lt;br/&gt;&lt;br/&gt;
&lt;i&gt;&lt;u&gt;Architectural Realization:&lt;/u&gt;&lt;/i&gt;
As you will notice in the example document, architectural realizations are references to architectural design decisions shown later on in the document.
&lt;br/&gt;&lt;br/&gt;
&lt;i&gt;&lt;u&gt;Goal Metrics:&lt;/u&gt;&lt;/i&gt;
Depending on your company's policies regarding development requirements and post mortem analysis, we may need to document measurable goal metrics to further make design decisions and to ultimately measure the success of the project.
&lt;br/&gt;&lt;br/&gt;
&lt;h4&gt;Justification&lt;/h4&gt;
Why do I suggest this kind of format for documenting requirements? Well hopefully the straight forward statements will not scare off non-technical stakeholders while still providing a technical bridge from those statements to developers. Furthermore, when the "Why did we do that?" kind of questions arise, a direct correlation from architectural and code decisions can be traced back to their respective requirement statements. Finally, it is the intent that documenting a formal statement (hopefully approved statement), lends itself to reduce ad hoc scope creep. Or at least if scope creep does happen, we can at least show in post mortem the number of changes after initial development began.
&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/321913728519024524-723737220041674997?l=allthingscs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/onTOXBF-li5mPPo3ypTExk6hY3Y/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/onTOXBF-li5mPPo3ypTExk6hY3Y/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/onTOXBF-li5mPPo3ypTExk6hY3Y/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/onTOXBF-li5mPPo3ypTExk6hY3Y/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/AllThingsCs/~4/Hj3grjzSKA8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allthingscs.blogspot.com/feeds/723737220041674997/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allthingscs.blogspot.com/2011/03/documenting-software-architectural.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/723737220041674997?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/723737220041674997?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/AllThingsCs/~3/Hj3grjzSKA8/documenting-software-architectural.html" title="Documenting Software Architectural Requirements" /><author><name>bh</name><uri>http://www.blogger.com/profile/02885141522169238049</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://2.bp.blogspot.com/-XTV5rmRh8TA/TXLmwmOXtgI/AAAAAAAAABo/gKL0C70swj0/s220/CleanedUpBryan3.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://allthingscs.blogspot.com/2011/03/documenting-software-architectural.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0AGRX44fSp7ImA9Wx9aF0U.&quot;"><id>tag:blogger.com,1999:blog-321913728519024524.post-3183174635022297620</id><published>2011-03-10T12:42:00.000-08:00</published><updated>2011-03-10T12:42:04.035-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-10T12:42:04.035-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Coding Practices" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>Weakly Typed vs Strongly Typed Objects</title><content type="html">What is the difference between weakly typed and strongly typed objects? When should I use weakly typed objects or strongly typed objects? Within the context of the &lt;a href="http://msdn.microsoft.com/en-us/vcsharp/aa336809"&gt;C# language&lt;/a&gt; I hope to give some insight on this subject. I think the best way to understand these diametrical types is to look at various code examples in comparison.&lt;br /&gt;
&lt;h5&gt;




Example 1&lt;/h5&gt;
&lt;div style="border: 1px solid gray; padding: 20px;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;string&lt;/span&gt;
myStringValue = &lt;span style="color: #a31515;"&gt;"43.3"&lt;/span&gt;;&amp;nbsp; &lt;span style="color: green;"&gt;// Weakly Typed&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;double&lt;/span&gt;
myDoubleValue = 43.3d;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// Strongly Typed&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;
This first example is fairly simple. What is the difference? Well obviously one variable is type
&lt;i&gt;string&lt;/i&gt; and the other is &lt;i&gt;double&lt;/i&gt;. But what makes the string type weak and the
double type strong? The double type is more restrictive that the string type.
Thus, all possible double values in myDoubleValue can also be stored with their string equivalent in myStringValue. But, not all possible values for myStringValue can be stored in myDoubleValue. We can generalize our understanding to the following statements:
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;i&gt;Strongly Typed objects are more restrictive than Weakly Typed objects.&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;All possible values for a Strongly Type object can be represented in a Weakly Typed object. But not all possible values for the same Weakly Typed object can be represented in the Strongly Typed object.&lt;/i&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h5&gt;





Example 2&lt;/h5&gt;
&lt;div style="border: 1px solid gray; overflow: auto; padding: 20px; white-space: nowrap;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: green;"&gt;// Weakly Typed&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;"&gt;Dictionary&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;span style="color: blue;"&gt;string&lt;/span&gt;, &lt;span style="color: blue;"&gt;double&lt;/span&gt;&amp;gt; myDictionary = &lt;span style="color: blue;"&gt;new&lt;/span&gt;
&lt;span style="color: #2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color: blue;"&gt;string&lt;/span&gt;,
&lt;span style="color: blue;"&gt;double&lt;/span&gt;&amp;gt;();&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;myDictionary.Add(&lt;span style="color: #a31515;"&gt;"A"&lt;/span&gt;, 43.3d);&lt;/span&gt;
&lt;br /&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;myDictionary.Add(&lt;span style="color: #a31515;"&gt;"B"&lt;/span&gt;, -24.0d);&lt;/span&gt;
&lt;br /&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;myDictionary.Add(&lt;span style="color: #a31515;"&gt;"C"&lt;/span&gt;, 1000.45d);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: green; font-family: Consolas; font-size: 9.5pt;"&gt;// Strongly Typed&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;"&gt;MyClass&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; myClass = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;MyClass&lt;/span&gt;()&lt;/span&gt;
&lt;br /&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;{&lt;/span&gt;
&lt;br /&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A = 43.3d,&lt;/span&gt;
&lt;br /&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; B = -24.0d,&lt;/span&gt;
&lt;br /&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C = 1000.45d&lt;/span&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;
&lt;br /&gt;};&lt;/span&gt;&lt;/div&gt;
In this example we want to access some stored values for A, B, and C. myDictionary is the weakly typed object and myClass is the strongly typed object. We can get and set our values in myDictionary via a string key. Using a MyClass type we get and set our values via the class properties. In the &lt;a href="http://www.microsoft.com/net/"&gt;.NET Framework&lt;/a&gt; libraries, types like myDictionary are fairly common. A few examples include &lt;a href="http://www.asp.net/"&gt;ASP.NET&lt;/a&gt;'s &lt;a href="http://msdn.microsoft.com/en-us/library/ms178581.aspx"&gt;Session&lt;/a&gt;, multiple &lt;a href="http://msdn.microsoft.com/en-us/library/h43ks021%28v=vs.71%29.aspx"&gt;ADO.NET&lt;/a&gt; objects like &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.dataset.aspx"&gt;DataSet&lt;/a&gt;, and the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx"&gt;XmlDocument&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
When should I use weakly typed objects or strongly typed objects?&lt;/h4&gt;
In most cases you should avoid weakly typed objects. Why?
&lt;br /&gt;
&lt;h5&gt;Case 1&lt;/h5&gt;
&lt;i&gt;&lt;strong&gt;Bad:&lt;/strong&gt;&lt;/i&gt; Suppose we used the weakly typed object, myStringValue in &lt;i&gt;Example 1&lt;/i&gt; in our application. Now somewhere deep in our code myStringValue was set to a non-double like value such as "nevermind." Why was it set to that? Who knows, strange code has a way of sneaking in. When will we know that that was an error? Hopefully at least while testing the runtime of our application. But no guarantees right. You will probably find out the error when a runtime exception was throw in production.
&lt;br/&gt;
&lt;br/&gt;
&lt;i&gt;&lt;strong&gt;Good:&lt;/strong&gt;&lt;/i&gt; Instead, we will use myDoubleValue, the strongly typed object. Why is this better? If any code tries sneak in and set myDoubleValue = "nevermind", then we will know the error at compile time instead of runtime. Anytime we can check our code for errors at compile time is far more preferable than at runtime. Less errors in production == less costs and management headaches (that could be a lengthy discussion on its own).
&lt;br /&gt;
&lt;br /&gt;
&lt;h5&gt;Case 2&lt;/h5&gt;
&lt;i&gt;&lt;strong&gt;Bad:&lt;/strong&gt;&lt;/i&gt; What if we have in multiple places of our code some kind of logical access like &lt;strong&gt;if (myDictionary["A"] &gt; 0.0d)...&lt;/strong&gt;? Now what happens when we no longer use "A"? Again we may not know about any errors until runtime.
&lt;br /&gt;&lt;br /&gt;
&lt;i&gt;&lt;strong&gt;Good:&lt;/strong&gt;&lt;/i&gt; In contrast, if we used the MyClass type instead and we had such logical code as &lt;strong&gt;if (myClass.A &gt; 0.0d)...&lt;/strong&gt;, then when we remove the property MyClass.A from our code and we compile, we will see immediately everywhere in our code errors where myClass.A is accessed.
&lt;br /&gt;
&lt;br/&gt;
&lt;h4&gt;Conclusion&lt;/h4&gt;
Weakly typed objects do have their place. For instance, within the scope of designing a framework, I believe the designers of the .NET Framework made good decisions to have some of the runtime objects as weakly typed (that would also be a lengthy discussion). However, you should avoid using weakly typed objects when you can, but there is no need to be too ridged.
&lt;br /&gt;&lt;br /&gt;
One more thing (a practical example); typically in my ASP.NET applications, I will keep a single session variable, such as Session["MySession"] = new MySession(). This allows me to limit my weakly typed Session object access to a single point (one spot in my code where I will get or set the Session object). I will then define my MySession class to act as a &lt;a href="http://www.dofactory.com/Patterns/PatternComposite.aspx"&gt;composite structure&lt;/a&gt; hierarchy with all my other variables and objects pertaining to the user's session. This will keep most of my code strongly typed with some very limited weakly typed access.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/321913728519024524-3183174635022297620?l=allthingscs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/cggPnn6QVsjweWMvrLYf__uWvRQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cggPnn6QVsjweWMvrLYf__uWvRQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/cggPnn6QVsjweWMvrLYf__uWvRQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cggPnn6QVsjweWMvrLYf__uWvRQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/AllThingsCs/~4/xyeheKMmWMA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allthingscs.blogspot.com/feeds/3183174635022297620/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allthingscs.blogspot.com/2011/03/weakly-typed-vs-strongly-typed-objects.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/3183174635022297620?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/3183174635022297620?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/AllThingsCs/~3/xyeheKMmWMA/weakly-typed-vs-strongly-typed-objects.html" title="Weakly Typed vs Strongly Typed Objects" /><author><name>bh</name><uri>http://www.blogger.com/profile/02885141522169238049</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://2.bp.blogspot.com/-XTV5rmRh8TA/TXLmwmOXtgI/AAAAAAAAABo/gKL0C70swj0/s220/CleanedUpBryan3.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://allthingscs.blogspot.com/2011/03/weakly-typed-vs-strongly-typed-objects.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk8ERXk5fSp7ImA9WhRRF0g.&quot;"><id>tag:blogger.com,1999:blog-321913728519024524.post-1397917007024775873</id><published>2011-03-10T07:34:00.000-08:00</published><updated>2011-12-01T07:53:24.725-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-01T07:53:24.725-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="LINQ Perfomance" /><category scheme="http://www.blogger.com/atom/ns#" term="LINQ" /><category scheme="http://www.blogger.com/atom/ns#" term="Performance" /><category scheme="http://www.blogger.com/atom/ns#" term="Optimization" /><title>Linq Performance</title><content type="html">&lt;a href="https://sites.google.com/site/allthingscs/LinqPerformanceTests.zip?attredirects=0&amp;amp;d=1"&gt;&lt;span style="font-size: xx-small;"&gt;Download Example&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: xx-small;"&gt;(UPDATE 11/30/2011: I made some clarifications to this article based on some healthy criticism from my friend at &lt;a href="http://ox.no/posts/linq-vs-loop-a-performance-test"&gt;http://ox.no/posts/linq-vs-loop-a-performance-test&lt;/a&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;








LINQ Deferred Execution (a very brief explanation)&lt;/h4&gt;
&lt;br /&gt;
Once understood, &lt;a href="http://msdn.microsoft.com/en-us/library/bb308959.aspx"&gt;LINQ&lt;/a&gt; offers a quick way to create &lt;a href="http://en.wikipedia.org/wiki/Query_language"&gt;query language&lt;/a&gt; statements (like &lt;a href="http://en.wikipedia.org/wiki/SQL"&gt;SQL&lt;/a&gt;) for &lt;a href="http://en.wikipedia.org/wiki/Object-oriented_programming"&gt;object-oriented&lt;/a&gt; development. However, it is critical to understand &lt;a href="http://msdn.microsoft.com/en-us/library/bb943859.aspx"&gt;deferred execution&lt;/a&gt; for LINQ (i.e. the code is not run until the results of the query need to be evaluated). I highly recommend &lt;a href="http://blogs.msdn.com/b/charlie/archive/2007/12/09/deferred-execution.aspx"&gt;http://blogs.msdn.com/b/charlie/archive/2007/12/09/deferred-execution.aspx&lt;/a&gt; as a good read.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;














Performance Study Explanation&lt;/h4&gt;
The general approach to this study is to load up some objects with some random data. Then do a comparison of the resulting performance between the LINQ iterations verses the for loop iterations. Furthermore, I have included one example where iterating with LINQ is a good choice (Performance Test A) and another example where iterating through LINQ is a bad choice (Performance Test B).&lt;br /&gt;
&lt;br /&gt;
Before showing the test examples, it should be noted that the working sets are preloaded with 10,000,000 dummy objects as is shown in the GenerateList() method below. The entire source code for the tests can be &lt;a href="https://sites.google.com/site/allthingscs/LinqPerformanceTests.zip?attredirects=0&amp;amp;d=1"&gt;downloaded here&lt;/a&gt;.&lt;br /&gt;
&lt;div style="border: 1px solid gray; padding: 20px;"&gt;
&lt;br /&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;public&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;List&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;
GenerateList()&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;int&lt;/span&gt; i;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;List&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt;&amp;gt; list = &lt;span style="color: blue;"&gt;new&lt;/span&gt;
&lt;span style="color: #2b91af;"&gt;List&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;();&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Random&lt;/span&gt;
rand = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Random&lt;/span&gt;(&lt;span style="color: blue;"&gt;unchecked&lt;/span&gt;((&lt;span style="color: blue;"&gt;int&lt;/span&gt;)&lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now.Ticks));&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;for&lt;/span&gt; (i = 0;
i &amp;lt; 10000000; i++)&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list.Add(&lt;span style="color: blue;"&gt;new&lt;/span&gt;
&lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt;()&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A = rand.NextDouble()&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt;
list;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;h4&gt;













&amp;nbsp;&lt;/h4&gt;
&lt;h4&gt;














Performance Test A (the Good LINQ)&lt;/h4&gt;
&lt;i&gt;&lt;b&gt;Performance Test A Summary&lt;/b&gt;: On my machine set (1) performed 
better than set (2) by about 200 milliseconds and sets (1) and (2) were 
iterated the same number of times.&lt;/i&gt;
&lt;br /&gt;
&lt;div style="border: 1px solid gray; padding: 20px;"&gt;
&lt;br /&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;[&lt;span style="color: #2b91af;"&gt;TestMethod&lt;/span&gt;]&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;public&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt;
PerformanceTestA()&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;IEnumerable&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt;&amp;gt; queryResults;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;IEnumerable&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; staticResults;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;List&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; list = &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.GenerateList();&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;
start = &lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 1.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryResults = list.Where(d =&amp;gt; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.PickDummy(d)); &lt;span style="color: green;"&gt;// Execution deferred&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.WriteAccessCount(&lt;span style="color: #a31515;"&gt;"1. "&lt;/span&gt;); &lt;span style="color: green;"&gt;//
Should still be zero&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 1.a&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;foreach&lt;/span&gt; (&lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt; model &lt;span style="color: blue;"&gt;in&lt;/span&gt;
queryResults) &lt;span style="color: green;"&gt;// Query Executed&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; model.A.ToString();&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.WriteAccessCount(&lt;span style="color: #a31515;"&gt;"1.a"&lt;/span&gt;); &lt;span style="color: green;"&gt;//
Should be approx 15,000,000&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 1.b&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: blue;"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #a31515;"&gt;"1.b
Execution Time: {0}"&lt;/span&gt;, &lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now
- start));&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;//------------------------------------&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine();&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; start = &lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 2.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt;.AccessCount
= 0;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryResults = list.Where(d =&amp;gt; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.PickDummy(d)); &lt;span style="color: green;"&gt;// Execution deferred&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.WriteAccessCount(&lt;span style="color: #a31515;"&gt;"2. "&lt;/span&gt;); &lt;span style="color: green;"&gt;//
Should still be zero&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 2.a&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; staticResults = queryResults.ToArray(); &lt;span style="color: green;"&gt;// Query Executed Again&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.WriteAccessCount(&lt;span style="color: #a31515;"&gt;"2.a"&lt;/span&gt;); &lt;span style="color: green;"&gt;//
Should be 10,000,000&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 2.b&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;foreach&lt;/span&gt; (&lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt; model &lt;span style="color: blue;"&gt;in&lt;/span&gt;
staticResults) &lt;span style="color: green;"&gt;// Query NOT Executed&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; model.A.ToString();&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.WriteAccessCount(&lt;span style="color: #a31515;"&gt;"2.b"&lt;/span&gt;); &lt;span style="color: green;"&gt;//
Should be approx 15,000,000&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 2.c&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: blue;"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #a31515;"&gt;"2.c
Execution Time: {0}"&lt;/span&gt;, &lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now
- start));&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
I should note that the access of property DummyModel.A property is accessed 15,000,000 times because the PerformanceUtility.PickDummy() method picks all A values &amp;gt;= 0.5. This means the initial iteration for choosing which DummyModels to be include in our set will be 10,000,000. Thus, the resulting list will contain 5,000,000 items. Therefore any subsequent iterations will only be 5,000,000.&lt;br /&gt;
&lt;br /&gt;
But wait, why did LINQ execute faster than the for loop if they both did the same number of iterations? Well to put it bluntly, apparently one of the perks for using LINQ is some kind of compiler optimization that your average for loop will not have &lt;span style="font-size: x-small;"&gt;(&lt;i&gt;&lt;b&gt;Pending Fact Check&lt;/b&gt;: I'd like to have some sort of confirmation from an official source about this assumption. If anyone has any info from a reliable source, let me know.&lt;/i&gt;).&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;













Performance Test B (the Bad LINQ)&lt;/h4&gt;
&lt;i&gt;&lt;b&gt;Performance Test B Summary&lt;/b&gt;: On my machine set (2) performed 
better than set (1) by about 900 milliseconds and set (1) required 20,000,000 more iterations than set (2) for the same functionality.&lt;/i&gt;
&lt;br /&gt;
&lt;div style="border: 1px solid gray; padding: 20px;"&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;[&lt;span style="color: #2b91af;"&gt;TestMethod&lt;/span&gt;]&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;public&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt;
PerformanceTestB()&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt;&amp;gt; queryResults;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt;&amp;gt; staticResults;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt;&amp;gt; list = &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.GenerateList();&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;
start = &lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 1.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryResults = list.Where(d =&amp;gt; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.PickDummy(d)); &lt;span style="color: green;"&gt;// Execution deferred&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.WriteAccessCount(&lt;span style="color: #a31515;"&gt;"1. "&lt;/span&gt;); &lt;span style="color: green;"&gt;//
Should still be zero&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 1.a&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryResults.ToArray(); &lt;span style="color: green;"&gt;// Query Executed&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.WriteAccessCount(&lt;span style="color: #a31515;"&gt;"1.a"&lt;/span&gt;); &lt;span style="color: green;"&gt;//
Should be 10,000,000&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 1.b&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;foreach&lt;/span&gt; (&lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt; model &lt;span style="color: blue;"&gt;in&lt;/span&gt;
queryResults) &lt;span style="color: green;"&gt;// Query Executed Again&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; model.A.ToString();&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.WriteAccessCount(&lt;span style="color: #a31515;"&gt;"1.b"&lt;/span&gt;); &lt;span style="color: green;"&gt;//
Should be approx 25,000,000&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 1.c&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;foreach&lt;/span&gt; (&lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt; model &lt;span style="color: blue;"&gt;in&lt;/span&gt;
queryResults) &lt;span style="color: green;"&gt;// Query Executed Again&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; model.A.ToString();&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.WriteAccessCount(&lt;span style="color: #a31515;"&gt;"1.c"&lt;/span&gt;); &lt;span style="color: green;"&gt;//
Should be approx 40,000,000&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 1.d&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: blue;"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #a31515;"&gt;"1.d
Execution Time: {0}"&lt;/span&gt;, &lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now
- start));&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;//------------------------------------&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine();&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; start = &lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 2.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt;.AccessCount
= 0;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryResults = list.Where(d =&amp;gt; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.PickDummy(d)); &lt;span style="color: green;"&gt;// Execution deferred&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.WriteAccessCount(&lt;span style="color: #a31515;"&gt;"2. "&lt;/span&gt;); &lt;span style="color: green;"&gt;//
Should still be zero&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 2.a&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; staticResults = queryResults.ToArray(); &lt;span style="color: green;"&gt;// Query Executed Again&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.WriteAccessCount(&lt;span style="color: #a31515;"&gt;"2.a"&lt;/span&gt;); &lt;span style="color: green;"&gt;//
Should be 10,000,000&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 2.b&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;foreach&lt;/span&gt; (&lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt; model &lt;span style="color: blue;"&gt;in&lt;/span&gt;
staticResults) &lt;span style="color: green;"&gt;// Query NOT Executed&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; model.A.ToString();&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.WriteAccessCount(&lt;span style="color: #a31515;"&gt;"2.b"&lt;/span&gt;); &lt;span style="color: green;"&gt;//
Should be approx 15,000,000&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 2.c&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;foreach&lt;/span&gt; (&lt;span style="color: #2b91af;"&gt;DummyModel&lt;/span&gt; model &lt;span style="color: blue;"&gt;in&lt;/span&gt;
staticResults) &lt;span style="color: green;"&gt;// Query NOT Executed&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; model.A.ToString();&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;PerformanceUtility&lt;/span&gt;.WriteAccessCount(&lt;span style="color: #a31515;"&gt;"2.c"&lt;/span&gt;); &lt;span style="color: green;"&gt;//
Should be approx 20,000,000&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;// 2.d&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: blue;"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #a31515;"&gt;"2.d
Execution Time: {0}"&lt;/span&gt;, &lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now
- start));&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
Whoa! Why did LINQ take so many more iterations than the for loop? Well, this is definitely a direct result of deferred execution. If I was a developer who had no understanding of deferred execution (of which I did at first), I might make this performance mistake. Look at the comments in the code carefully. You'll notice that in each iteration LINQ does a query execution each and every time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;









Conclusion&lt;/h4&gt;
A simple knowledge and building some of your own tests for deferred execution can quickly get you up to speed for optimization. Ultimately, whether to load your LINQ results into a static collection or to allow deferred execution is going to be a case by case decision. Have fun and good luck!&lt;br /&gt;
&lt;br /&gt;
&lt;a href="https://sites.google.com/site/allthingscs/LinqPerformanceTests.zip?attredirects=0&amp;amp;d=1"&gt;&lt;span style="font-size: xx-small;"&gt;Download Example&lt;/span&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/321913728519024524-1397917007024775873?l=allthingscs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/aXdgIEEbIlPeQq-PIHuLEPyQBro/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/aXdgIEEbIlPeQq-PIHuLEPyQBro/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/aXdgIEEbIlPeQq-PIHuLEPyQBro/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/aXdgIEEbIlPeQq-PIHuLEPyQBro/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/AllThingsCs/~4/EECrZcRCYXQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allthingscs.blogspot.com/feeds/1397917007024775873/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allthingscs.blogspot.com/2011/03/linq-performance.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/1397917007024775873?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/1397917007024775873?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/AllThingsCs/~3/EECrZcRCYXQ/linq-performance.html" title="Linq Performance" /><author><name>bh</name><uri>http://www.blogger.com/profile/02885141522169238049</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://2.bp.blogspot.com/-XTV5rmRh8TA/TXLmwmOXtgI/AAAAAAAAABo/gKL0C70swj0/s220/CleanedUpBryan3.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://allthingscs.blogspot.com/2011/03/linq-performance.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkIGQnY-fip7ImA9WhZSEEU.&quot;"><id>tag:blogger.com,1999:blog-321913728519024524.post-1452158393736081089</id><published>2011-03-05T17:33:00.000-08:00</published><updated>2011-03-25T14:28:43.856-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-25T14:28:43.856-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="n-tier" /><category scheme="http://www.blogger.com/atom/ns#" term="mvc" /><category scheme="http://www.blogger.com/atom/ns#" term="3-tier" /><category scheme="http://www.blogger.com/atom/ns#" term="Software Architecture" /><title>MVC vs 3-Tier Pattern</title><content type="html">I have had several people ask me what the difference is between &lt;a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller"&gt;MVC (Model View Controller)&lt;/a&gt; and &lt;a href="http://dotnetslackers.com/articles/net/IntroductionTo3TierArchitecture.aspx"&gt;Three-Tier&lt;/a&gt; architectural patterns. It is my intent to clarify the confusion by comparing the two patterns side-by-side. At least in part, I believe the source of some of the confusion is that they both have three distinct layers or nodes in their respective diagrams.&lt;br /&gt;
&lt;br /&gt;
&lt;table style="width: 100%;"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://lh6.googleusercontent.com/-L6LXAlWzyJg/TXKtInyJ34I/AAAAAAAAABM/0BuKQOfvfnE/s1600/threetier.jpg" imageanchor="1"&gt;&lt;img border="0" height="200" src="https://lh6.googleusercontent.com/-L6LXAlWzyJg/TXKtInyJ34I/AAAAAAAAABM/0BuKQOfvfnE/s200/threetier.jpg" width="117" /&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;&lt;a href="https://lh6.googleusercontent.com/-sXFmzjIENrc/TXLU1rSxyFI/AAAAAAAAABU/61CmtYVuZyQ/s1600/mvc.jpg" imageanchor="1"&gt;&lt;img border="0" height="200" src="https://lh6.googleusercontent.com/-sXFmzjIENrc/TXLU1rSxyFI/AAAAAAAAABU/61CmtYVuZyQ/s200/mvc.jpg" width="185" /&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="font-size: 8px; text-align: center;"&gt;Three-Tier
&lt;/td&gt;
&lt;td style="font-size: 8px; text-align: center;"&gt;MVC
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
If you look carefully at each diagram you'll notice the &lt;a href="http://publib.boulder.ibm.com/infocenter/rtnlhelp/v6r0m0/index.jsp?topic=%2Fcom.ibm.xtools.modeler.doc%2Ftopics%2Fcassn.html"&gt;associations&lt;/a&gt; (arrow connectors) between the boxes are set up a little differently. &lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;


Three-Tier&lt;/h4&gt;
A 3-tiered system really is made up of layers (think of cake layers). The UI Layer has access to the Business Logic Layer, and the Business Layer has access to the Data Layer. But the UI Layer cannot directly access the Data Layer. In order for the UI Layer to access data, it must go through the Business Logic Layer via some kind of interface. If it helps, you could think of each layer as one big loosely coupled component with strict design rules of access between layers.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;


MVC (Model View Controller)&lt;/h4&gt;
In contrast, the MVC pattern obviously does not keep a layered system. The Contoller accesses the Model (a runtime data repository) and the View. The View then accesses the Model. Exactly how does that work? The Controller ultimately is the logical decision point. What sort of logic? Typically, the Controller will retrieve, build, or modify a Model base on some triggered action. The Controller then decides which View is appropriate via some internal logic. At that point the Controller will push the Model to View.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Note: &lt;/i&gt;Because I mostly develop with .NET, Microsoft has adopted the MVC pattern for ASP.NET with their own platform (see &lt;a href="http://www.asp.net/mvc"&gt;http://www.asp.net/mvc&lt;/a&gt;). You can certainly use the MVC pattern without Microsoft's platform, but why reinvent the wheel? I have been very happy using it so far.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;When Do I Choose Which Pattern?&lt;/h4&gt;
First of all, these two patterns are definitely not mutually exclusive. In fact in my experience they are quite harmonious. Often I use a &lt;a href="http://en.wikipedia.org/wiki/Multitier_architecture"&gt;multi-tiered architecture&lt;/a&gt;, such as a three-tiered architecture, for the overall architectural structure. Then, within the UI Layer, I use MVC. Something like the diagram below.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://lh5.googleusercontent.com/-FzlhEomyE1c/TXLfvzRTXcI/AAAAAAAAABY/wEzfvP2v4pc/s1600/mvc3tiercombo.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="https://lh5.googleusercontent.com/-FzlhEomyE1c/TXLfvzRTXcI/AAAAAAAAABY/wEzfvP2v4pc/s320/mvc3tiercombo.jpg" width="305" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/321913728519024524-1452158393736081089?l=allthingscs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/JD73N9wYHNEVPgh4mIqyzfo6zYE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/JD73N9wYHNEVPgh4mIqyzfo6zYE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/JD73N9wYHNEVPgh4mIqyzfo6zYE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/JD73N9wYHNEVPgh4mIqyzfo6zYE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/AllThingsCs/~4/ACS_DUFFiqI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allthingscs.blogspot.com/feeds/1452158393736081089/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allthingscs.blogspot.com/2011/03/mvc-vs-3-tier-pattern.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/1452158393736081089?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/1452158393736081089?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/AllThingsCs/~3/ACS_DUFFiqI/mvc-vs-3-tier-pattern.html" title="MVC vs 3-Tier Pattern" /><author><name>bh</name><uri>http://www.blogger.com/profile/02885141522169238049</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://2.bp.blogspot.com/-XTV5rmRh8TA/TXLmwmOXtgI/AAAAAAAAABo/gKL0C70swj0/s220/CleanedUpBryan3.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lh6.googleusercontent.com/-L6LXAlWzyJg/TXKtInyJ34I/AAAAAAAAABM/0BuKQOfvfnE/s72-c/threetier.jpg" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://allthingscs.blogspot.com/2011/03/mvc-vs-3-tier-pattern.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk4FRnw4fSp7ImA9Wx9aE0g.&quot;"><id>tag:blogger.com,1999:blog-321913728519024524.post-5338822568499442804</id><published>2009-07-01T18:58:00.000-07:00</published><updated>2011-03-05T11:55:17.235-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-05T11:55:17.235-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JQuery" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><title>jQuery Plugins with ASP.NET Controls</title><content type="html">After years of frustration with JavaScript and cross browser compatibility, a friend of mine introduced me to the wonderful world of &lt;a href="http://www.jquery.com/"&gt;jQuery&lt;/a&gt;. Then, after also discovering an endless amount of free &lt;a href="http://plugins.jquery.com/"&gt;plugin libraries&lt;/a&gt; for jQuery, I immediately went to work to develop reusable user controls for our internal development library. In this example, I will be using the &lt;a href="http://craigsworks.com/projects/qtip/"&gt;qtip plugin&lt;/a&gt;:&lt;br /&gt;
&lt;br /&gt;
1. First create an .ascx file with a placeholder.&lt;br /&gt;
&lt;div style="background-color: #eeeeee; border: 1px solid gray; color: black; font-family: courier new; font-size: 12px; padding: 10px;"&gt;
&lt;div id=""&gt;
&amp;lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Tootip.ascx.cs" Inherits="JQueryInterfaceTests.Controls.Tootip" %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div id=""&gt;
" style="max-height:&amp;lt;%= this.MaxHeight.ToString() %&amp;gt;px; overflow:auto;"&amp;gt;&lt;br /&gt;
&lt;asp:placeholder id="phPlaceHolder" runat="server"&gt;&lt;br /&gt;&lt;/asp:placeholder&gt;&lt;/div&gt;
&lt;asp:placeholder id="phPlaceHolder" runat="server"&gt;&lt;br /&gt;&lt;/asp:placeholder&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Next, you will need to take advantage of registering your .js files in page's &lt;a href="http://msdn.microsoft.com/en-us/library/ms178207.aspx"&gt;ClientScript&lt;/a&gt;. This is important because if you drop more than one instance of your control on the page, then you only want to include your .js file once.&lt;br /&gt;
&lt;br /&gt;
&lt;div style="background-color: #eeeeee; border: 1px solid gray; color: black; font-family: courier new; font-size: 12px; padding: 10px;"&gt;
public class QTipControl : UserControl, INamingContainer&lt;br /&gt;
{&lt;br /&gt;
protected override void OnLoad(EventArgs e)&lt;br /&gt;
{&lt;br /&gt;
string jqPath = this.Page.ResolveClientUrl("~/Javascripts/jquery-1.3.2.js");&lt;br /&gt;
&lt;br /&gt;
if (!this.Page.ClientScript.IsClientScriptIncludeRegistered(jqPath))&lt;br /&gt;
this.Page.ClientScript.RegisterClientScriptInclude(jqPath, jqPath);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// More Code Here&lt;br /&gt;
}&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Also, you will need to set all attributes that will be abstracted to the properties of the user control for ease of use.&lt;br /&gt;
&lt;br /&gt;
&lt;div style="background-color: #eeeeee; border: 1px solid gray; color: black; font-family: courier new; font-size: 12px; padding: 10px;"&gt;
#region Events&lt;br /&gt;
protected override void CreateChildControls()&lt;br /&gt;
{&lt;br /&gt;
//base.CreateChildControls();&lt;br /&gt;
}&lt;br /&gt;
#endregion&lt;br /&gt;
&lt;br /&gt;
#region Properties&lt;br /&gt;
public string MouseOverClientID&lt;br /&gt;
{&lt;br /&gt;
get;&lt;br /&gt;
set;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public int MaxHeight&lt;br /&gt;
{&lt;br /&gt;
get;&lt;br /&gt;
set;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public Position TargetPosition&lt;br /&gt;
{&lt;br /&gt;
get;&lt;br /&gt;
set;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public Position TooltipPosition&lt;br /&gt;
{&lt;br /&gt;
get;&lt;br /&gt;
set;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public Position ArrowPosition&lt;br /&gt;
{&lt;br /&gt;
get;&lt;br /&gt;
set;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public Color BorderColor&lt;br /&gt;
{&lt;br /&gt;
get;&lt;br /&gt;
set;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public Color BackgroundColor&lt;br /&gt;
{&lt;br /&gt;
get;&lt;br /&gt;
set;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/// &lt;summary&gt;&lt;br /&gt;/// If false, then tooltip hides when user unfocuses from the MouseOverClientID element.&lt;br /&gt;/// If true, then tooltip remains and can be interacted with until focus on to another element on the page occurs.&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;
public bool IsSticky&lt;br /&gt;
{&lt;br /&gt;
get;&lt;br /&gt;
set;&lt;br /&gt;
}&lt;br /&gt;
#endregion&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Finally, you will need to write any initialization for each client instance. Also, you will need to put the content into your placeholder (notice the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.inamingcontainer.aspx"&gt;INamingContainer&lt;/a&gt;). Now here is how your OnLoad ought to look now.&lt;br /&gt;
&lt;br /&gt;
&lt;div style="background-color: #eeeeee; border: 1px solid gray; color: black; font-family: courier new; font-size: 12px; padding: 10px;"&gt;
[ParseChildren(true)]&lt;br /&gt;
public abstract class MyWrapperControl : UserControl, INamingContainer&lt;br /&gt;
{&lt;br /&gt;
protected override void OnLoad(EventArgs e)&lt;br /&gt;
{&lt;br /&gt;
string jqPath = this.Page.ResolveClientUrl("~/Javascripts/jquery-1.3.2.js");&lt;br /&gt;
string qtipPath = this.Page.ResolveClientUrl(ResourcePaths.JQueryQtipTootipPath);&lt;br /&gt;
&lt;br /&gt;
if (!this.Page.ClientScript.IsClientScriptIncludeRegistered(jqPath))&lt;br /&gt;
this.Page.ClientScript.RegisterClientScriptInclude(jqPath, jqPath);&lt;br /&gt;
&lt;br /&gt;
if (!this.Page.ClientScript.IsClientScriptIncludeRegistered(qtipPath))&lt;br /&gt;
this.Page.ClientScript.RegisterClientScriptInclude(qtipPath, qtipPath);&lt;br /&gt;
&lt;br /&gt;
// Write to placeholder&lt;br /&gt;
using (System.IO.StringWriter sw = new System.IO.StringWriter(sb))&lt;br /&gt;
{&lt;br /&gt;
using (HtmlTextWriter htw = new HtmlTextWriter(sw))&lt;br /&gt;
{&lt;br /&gt;
if (this.Content != null)&lt;br /&gt;
this.Content.InstantiateIn(this.phPlaceHolder);&lt;br /&gt;
&lt;br /&gt;
base.CreateChildControls();&lt;br /&gt;
base.Render(htw);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if (!this.Page.ClientScript.IsClientScriptBlockRegistered(this.ClientID))&lt;br /&gt;
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(),&lt;br /&gt;
this.ClientID,&lt;br /&gt;
"$(document).ready(function(){" +&lt;br /&gt;
&lt;br /&gt;
// Qtip Init&lt;br /&gt;
"$(\"#" + this.MouseOverClientID + "\").qtip({" +&lt;br /&gt;
"content: {text:'" + sb.ToString().Replace("'", "\\'").Replace(System.Environment.NewLine, string.Empty) + "'}" +&lt;br /&gt;
",position:{corner:{target:'" + this.TargetPosition + "',tooltip:'" + this.TooltipPosition + "'}}" +&lt;br /&gt;
",style:{tip:'" + this.ArrowPosition + "',name:'cream',background:'" + this.GetRGB(this.BackgroundColor) + "',color:'black',border:{radius:3,color:'" + this.GetRGB(this.BorderColor) + "'}}" +&lt;br /&gt;
(this.IsSticky ? ",hide:'unfocus'" : string.Empty) +&lt;br /&gt;
",show:{solo:true,effect:{type:'none',length:100}}" +&lt;br /&gt;
",hide:{effect:{type:'none',length:100}}" +&lt;br /&gt;
"});" +&lt;br /&gt;
&lt;br /&gt;
"});",&lt;br /&gt;
true);&lt;br /&gt;
}&lt;br /&gt;
// More Code Here //&lt;br /&gt;
[TemplateContainer(typeof(JQueryUserControl))]&lt;br /&gt;
[PersistenceMode(PersistenceMode.InnerProperty)]&lt;br /&gt;
public ITemplate Content&lt;br /&gt;
{&lt;br /&gt;
get;&lt;br /&gt;
set;&lt;br /&gt;
}&lt;br /&gt;
}&lt;/div&gt;
&lt;br /&gt;
That's it, enjoy!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/321913728519024524-5338822568499442804?l=allthingscs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/8lci_ebnFTqZSbVklvpXjAcTQRo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8lci_ebnFTqZSbVklvpXjAcTQRo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/8lci_ebnFTqZSbVklvpXjAcTQRo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8lci_ebnFTqZSbVklvpXjAcTQRo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/AllThingsCs/~4/9yAXdiNC7Ao" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allthingscs.blogspot.com/feeds/5338822568499442804/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allthingscs.blogspot.com/2009/07/jquery-plugins-with-aspnet-controls.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/5338822568499442804?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/5338822568499442804?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/AllThingsCs/~3/9yAXdiNC7Ao/jquery-plugins-with-aspnet-controls.html" title="jQuery Plugins with ASP.NET Controls" /><author><name>bh</name><uri>http://www.blogger.com/profile/02885141522169238049</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://2.bp.blogspot.com/-XTV5rmRh8TA/TXLmwmOXtgI/AAAAAAAAABo/gKL0C70swj0/s220/CleanedUpBryan3.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://allthingscs.blogspot.com/2009/07/jquery-plugins-with-aspnet-controls.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0MFRnc-cSp7ImA9WxJVFU0.&quot;"><id>tag:blogger.com,1999:blog-321913728519024524.post-6432204096340252871</id><published>2009-06-29T20:18:00.000-07:00</published><updated>2009-07-01T19:23:37.959-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-07-01T19:23:37.959-07:00</app:edited><title>Localization with Strongly-Typed Keys</title><content type="html">I came across this issue while working on an &lt;a href="http://www.asp.net/mvc/"&gt;MVC&lt;/a&gt; application in VS 2008. The project required localization to be setup such that future phases could easily incorporate languages other than English. As expected, I initially added local resources in their respective resx files.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Problem:&lt;/span&gt; As usual, I was thinking of improved ways to extend long term management of the application. When working with string-keyed references, I typically like to think of ways to enumerate or use static constants for strongly-typed keys instead of loosely defined strings. So I thought maybe I could build some kind of custom tool or a pre-build event executable to read through the resx xml and create code that would reflect the keyed strings. However, after some googling, I discovered that the solution was right under my nose; VS 2008 does this for me. At the top of the GUI for the resx file in VS is a dropdown menu with the label &lt;span style="font-style: italic;"&gt;Access Modifier&lt;/span&gt;. When I selected &lt;span style="font-style: italic;"&gt;Public&lt;/span&gt; in the dropdown, a code behind file appeared for my resx file. It had the strongly-typed key constants just as I wanted so that I could access the keys with intellisense.&lt;br /&gt;&lt;br /&gt;For all effective purposes this seemed to work great until I added another resx file for the Spanish language. After some time looking into this, I discovered that when I changed the dropdown to public, my English resx file changed from a &lt;span style="font-style: italic;"&gt;Content&lt;/span&gt; page (&lt;span style="font-style: italic;"&gt;see Build Action&lt;/span&gt; field in the file's properties) to an &lt;span style="font-style: italic;"&gt;Embedded Resource&lt;/span&gt;. So this means that instead of loading the resource file from IO during runtime, it will embed the file directly into my dll at compile time. However, accessing the corresponding Spanish file was not localization as usual. I needed to set the es.resx file to also have &lt;span style="font-style: italic;"&gt;Embedded Resource&lt;/span&gt; in the &lt;span style="font-style: italic;"&gt;Build Action&lt;/span&gt;&lt;span&gt;, because localization at runtime now looks for the embedded resource files, not the IO files. &lt;/span&gt;There is just one thing to remember, make sure that the &lt;span style="font-style: italic;"&gt;Access Modifier&lt;/span&gt; is set to &lt;span style="font-style: italic;"&gt;No code generation&lt;/span&gt; for the Spanish file, don't think this will be set exactly how you set your primary language resx file with the dropdown menu in the GUI, because we already defined the keys in the primary language file.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Solution&lt;/span&gt;:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Set the the primary resx file to &lt;span style="font-style: italic;"&gt;Public &lt;/span&gt;from the &lt;span style="font-style: italic;"&gt;Access Modifier &lt;/span&gt;dropdown.&lt;/li&gt;&lt;li&gt;Set all other language resx sister files to &lt;span style="font-style: italic;"&gt;Embedded Resource&lt;/span&gt; from the &lt;span style="font-style: italic;"&gt;Build Action&lt;/span&gt; field in the respective file's property window.&lt;/li&gt;&lt;/ol&gt;Hope this is helpful:)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/321913728519024524-6432204096340252871?l=allthingscs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/w1f4NMuJ8SWJSLnB-Lw0YkcN3os/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/w1f4NMuJ8SWJSLnB-Lw0YkcN3os/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/w1f4NMuJ8SWJSLnB-Lw0YkcN3os/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/w1f4NMuJ8SWJSLnB-Lw0YkcN3os/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/AllThingsCs/~4/Quxj_aDWxTU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allthingscs.blogspot.com/feeds/6432204096340252871/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allthingscs.blogspot.com/2009/06/localization-strongly-typed-keys.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/6432204096340252871?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/321913728519024524/posts/default/6432204096340252871?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/AllThingsCs/~3/Quxj_aDWxTU/localization-strongly-typed-keys.html" title="Localization with Strongly-Typed Keys" /><author><name>bh</name><uri>http://www.blogger.com/profile/02885141522169238049</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://2.bp.blogspot.com/-XTV5rmRh8TA/TXLmwmOXtgI/AAAAAAAAABo/gKL0C70swj0/s220/CleanedUpBryan3.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://allthingscs.blogspot.com/2009/06/localization-strongly-typed-keys.html</feedburner:origLink></entry></feed>

