<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
    <channel>
        <title>Drop in the Bucket</title>
        <link>http://jeffkwak.com/blog/Default.aspx</link>
        <description>One coder in the sea of s/w knowledge</description>
        <language>en-US</language>
        <copyright>Jeff Kwak</copyright>
        <managingEditor>jeff.kwak@gmail.com</managingEditor>
        <generator>Subtext Version 1.9.5.176</generator>
        <image>
            <title>Drop in the Bucket</title>
            <url>http://jeffkwak.com/blog/images/RSS2Image.gif</url>
            <link>http://jeffkwak.com/blog/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/DropInTheBucket" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
            <title>There is no &amp;lsquo;I&amp;rsquo; in Code</title>
            <category>Really?!</category>
            <link>http://feedproxy.google.com/~r/DropInTheBucket/~3/2_yJ8UYcvOY/there-is-no-lsquoirsquo-in-code.aspx</link>
            <description>&lt;p&gt;I’m finally ready to say goodbye to Hungarian notation. I’m not just talking about strFirstName, nIndex, or even wcstrzCategoryCode. Those kinds of attacks on readability have finally disappeared like polio and small pox. I’m talking about prefacing an interface with an upper-case ‘I’.&lt;/p&gt;  &lt;p&gt;I recently had a discussion with a respected co-worker on this. His argument was that folk expect to see an interface prefixed  with an ‘I’. I get it. I even like to use it myself for humor: ICanBeClicked, ICanBeTypedIn, etc… However, my counter-argument was particularily good I thought. The ‘I’ adds nothing in terms of its meaning or readability. Moreover, it doesn’t matter if the interface happens to be an interface or an abstract class (or even a concrete class for that matter). The ‘I’ is a hold over from the dark days of VB4, COM programming, and other things that shall not be named.&lt;/p&gt;  &lt;p&gt;It’s taken a while for me to get here. Hi, my name is Jeff, and I’m a recovering Hungarian notation user.&lt;/p&gt;&lt;img src="http://jeffkwak.com/blog/aggbug/36.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/DropInTheBucket/~4/2_yJ8UYcvOY" height="1" width="1"/&gt;</description>
            <dc:creator>Jeff Kwak</dc:creator>
            <guid isPermaLink="false">http://jeffkwak.com/blog/archive/2009/05/31/there-is-no-lsquoirsquo-in-code.aspx</guid>
            <pubDate>Sun, 31 May 2009 21:03:47 GMT</pubDate>
            <comments>http://jeffkwak.com/blog/archive/2009/05/31/there-is-no-lsquoirsquo-in-code.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://jeffkwak.com/blog/comments/commentRss/36.aspx</wfw:commentRss>
            <trackback:ping>http://jeffkwak.com/blog/services/trackbacks/36.aspx</trackback:ping>
        <feedburner:origLink>http://jeffkwak.com/blog/archive/2009/05/31/there-is-no-lsquoirsquo-in-code.aspx</feedburner:origLink></item>
        <item>
            <title>Dependency Injection and the Controller Factory in ASP.NET MVC</title>
            <category>General</category>
            <category>MVC</category>
            <link>http://feedproxy.google.com/~r/DropInTheBucket/~3/c-tuoj6ClUc/dependency-injection-and-the-controller-factory-in-asp.net-mvc.aspx</link>
            <description>&lt;p&gt;Using an IoC is one of those things that can take a time or two to understand where it fits in and how it’s useful. Once you cross the energy barrier, it’s a color in your palette you can’t imagine missing.&lt;/p&gt;
&lt;p&gt;Imagine having a QuestionController that takes an interface called DomainRepository. The job of any concrete implementation of the DomainRepository will be to fetch various domain entities from a backing store.&lt;/p&gt;
&lt;pre&gt;  &lt;br /&gt;&lt;br /&gt;  public class QuestionController : Controller&lt;br /&gt;  {&lt;br /&gt;&lt;br /&gt;    private DomainRepository _repository;&lt;br /&gt;&lt;br /&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// Initializes a new instance of the &amp;lt;see cref="QuestionController"/&amp;gt; class.&lt;br /&gt;    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;param name="repository"&amp;gt;The domain repository provides a source for the domain model&amp;lt;/param&amp;gt;&lt;br /&gt;    public QuestionController(DomainRepository repository)&lt;br /&gt;    {&lt;br /&gt;      _repository = repository;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    //&lt;br /&gt;    // GET: /Question/List&lt;br /&gt;    public ActionResult List()&lt;br /&gt;    {&lt;br /&gt;      var questions = _repository.GetQuestions();&lt;br /&gt;      return View("List", questions);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;You’d like to use dependency injection to provide the concrete implementation so that you could switch it up for a mock or stub when testing, a Linq to SQL implementation during production, and to make switching to something else an easy task if needed in the future.&lt;/p&gt;
&lt;p&gt;The gotcha is that ASP.NET MVC, by default, requires its controllers to have default constructors. Luckily, ASP.NET MVC uses a ControllerBuilder to instantiate the controllers using a ControllerFactory. This is an extension point where we can provider our own factory, one that uses the IoC of choice to resolve the controller.&lt;/p&gt;
&lt;p&gt;First create the new ControllerFactory. Here, I’m using StructureMap as my IoC of choice, but this is all it takes.&lt;/p&gt;

&lt;pre&gt;

public class StructureMapControllerFactory : DefaultControllerFactory
{
  protected override IController GetControllerInstance(Type controllerType)
  {
    return ObjectFactory.GetInstance(controllerType) as IController;
  }
}

&lt;/pre&gt;

&lt;p&gt;Then in your bootstrapper, or in application start of your Global.asax, simply set the ControllerFactory&lt;/p&gt;

&lt;pre&gt;

ControllerBuilder.Current
  .SetControllerFactory(new StructureMapControllerFactory());

&lt;/pre&gt;

&lt;p&gt;An IoC container is a wonderful tool. It will now figure out how to construct the requested controller, and if that controller requires something else, how to make that, and if that something else requires something else, and so on, and so on…&lt;/p&gt;
&lt;p&gt;The way concrete types are registered to their interfaces varies based on the container. For structure map, the following entries in the bootstrapper suffice for this example.&lt;/p&gt;

&lt;pre&gt;

ObjectFactory.Initialize(factory =&amp;gt;
{
  factory.ForRequestedType&amp;lt;DomainRepository&amp;gt;()
    .TheDefaultIsConcreteType&amp;lt;FakeDomainRepository&amp;gt;();
});

&lt;/pre&gt;

&lt;p&gt; &lt;/p&gt;&lt;img src="http://jeffkwak.com/blog/aggbug/35.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/DropInTheBucket/~4/c-tuoj6ClUc" height="1" width="1"/&gt;</description>
            <dc:creator>Jeff Kwak</dc:creator>
            <guid isPermaLink="false">http://jeffkwak.com/blog/archive/2009/05/29/dependency-injection-and-the-controller-factory-in-asp.net-mvc.aspx</guid>
            <pubDate>Sat, 30 May 2009 03:48:56 GMT</pubDate>
            <comments>http://jeffkwak.com/blog/archive/2009/05/29/dependency-injection-and-the-controller-factory-in-asp.net-mvc.aspx#feedback</comments>
            <wfw:commentRss>http://jeffkwak.com/blog/comments/commentRss/35.aspx</wfw:commentRss>
            <trackback:ping>http://jeffkwak.com/blog/services/trackbacks/35.aspx</trackback:ping>
        <feedburner:origLink>http://jeffkwak.com/blog/archive/2009/05/29/dependency-injection-and-the-controller-factory-in-asp.net-mvc.aspx</feedburner:origLink></item>
        <item>
            <title>Selenium RC Permission Denied</title>
            <category>General</category>
            <link>http://feedproxy.google.com/~r/DropInTheBucket/~3/MoOxesDtUas/selenium-rc-permission-denied.aspx</link>
            <description>&lt;p&gt;I’ve been working on a high-level “DSL” for automating acceptance tests on web sites. Currently, the two drivers that manipulate the browser can be either &lt;a href="http://seleniumhq.org/projects/remote-control/"&gt;Selenium RC&lt;/a&gt; or &lt;a href="http://sourceforge.net/projects/ulti-swat"&gt;SWAT&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;When using IE7 as the browser on Selenium I received that arcane message: “Permission denied on session b08dbc4413c34824ad65a61115845b8a”. The forums were a little obtuse, but one thing that helped was changing the browser string from &lt;code&gt;*iexplore&lt;/code&gt; to &lt;code&gt;*iehta&lt;/code&gt;. It was still a little flaky. The key was calling &lt;code&gt;WaitForPageToLoad&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Perhaps it was a case of RTFM, but after changing the browser command to &lt;code&gt;*iehta&lt;/code&gt;, I noticed this message:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;you appear to be changing domains from http://localhost to http://www.google.com&lt;br /&gt;
Permission denied’ from the browser (unless it is running as *iehta or *chrome&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The combination of using the right browser command and calling &lt;code&gt;WaitForPageToLoad&lt;/code&gt; did the trick.&lt;/p&gt;&lt;img src="http://jeffkwak.com/blog/aggbug/33.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/DropInTheBucket/~4/MoOxesDtUas" height="1" width="1"/&gt;</description>
            <dc:creator>Jeff Kwak</dc:creator>
            <guid isPermaLink="false">http://jeffkwak.com/blog/archive/2009/05/16/selenium-rc-permission-denied.aspx</guid>
            <pubDate>Sat, 16 May 2009 15:55:30 GMT</pubDate>
            <comments>http://jeffkwak.com/blog/archive/2009/05/16/selenium-rc-permission-denied.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://jeffkwak.com/blog/comments/commentRss/33.aspx</wfw:commentRss>
            <trackback:ping>http://jeffkwak.com/blog/services/trackbacks/33.aspx</trackback:ping>
        <feedburner:origLink>http://jeffkwak.com/blog/archive/2009/05/16/selenium-rc-permission-denied.aspx</feedburner:origLink></item>
        <item>
            <title>What's Your Wordle?</title>
            <category>General</category>
            <link>http://feedproxy.google.com/~r/DropInTheBucket/~3/EwoEQXG8Bks/whats-your-wordle.aspx</link>
            <description>&lt;h3&gt;Visualizing Your Blog&lt;/h3&gt;

&lt;p&gt;
I've been into data visualizations lately. I'm inspired by &lt;a href="http://www.vimeo.com/1093745"&gt;code_swarm&lt;/a&gt; and &lt;a href="http://wordle.net/"&gt;wordle&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
Here's the wordle of my blog:
&lt;/p&gt;

&lt;div&gt;
  &lt;img src="http://www.jeffkwak.com/blog/postImages/what-is-your-wordle/wordle-my-blog.jpg" alt="weighted word cloud of the words on my blog" /&gt;
&lt;/div&gt;&lt;img src="http://jeffkwak.com/blog/aggbug/32.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/DropInTheBucket/~4/EwoEQXG8Bks" height="1" width="1"/&gt;</description>
            <dc:creator>Jeff Kwak</dc:creator>
            <guid isPermaLink="false">http://jeffkwak.com/blog/archive/2008/08/12/whats-your-wordle.aspx</guid>
            <pubDate>Wed, 13 Aug 2008 03:04:47 GMT</pubDate>
            <comments>http://jeffkwak.com/blog/archive/2008/08/12/whats-your-wordle.aspx#feedback</comments>
            <wfw:commentRss>http://jeffkwak.com/blog/comments/commentRss/32.aspx</wfw:commentRss>
            <trackback:ping>http://jeffkwak.com/blog/services/trackbacks/32.aspx</trackback:ping>
        <feedburner:origLink>http://jeffkwak.com/blog/archive/2008/08/12/whats-your-wordle.aspx</feedburner:origLink></item>
        <item>
            <title>Basic Databinding in XAML with Silverlight</title>
            <category>Silverlight</category>
            <link>http://feedproxy.google.com/~r/DropInTheBucket/~3/jBGeXERD9EA/basic-databinding-in-xaml-with-silverlight.aspx</link>
            <description>&lt;p&gt;There are a lot of really great detailed posts about databinding in your XAML application, in both Silverlight and Avalon (WPF). This isn't one of them :). This post will focus on the mechanics for a couple of ways you can make databinding work. There are many other, and arguably better, ways of doing these same simple things. I'm constantly suprised by how flexible WPF and XAML are in how they can be programmed; which is great when your wild and creative ideas work, and horrible when you can't accomplish the simpliest thing. &lt;/p&gt;
&lt;h3&gt;Binding Syntax&lt;/h3&gt;
&lt;p&gt;&lt;img alt="" src="http://www.jeffkwak.com/blog/postImages/basic-databinding-in-XAML-with-silverlight/databinding-syntax.png" /&gt; &lt;/p&gt;
&lt;p&gt;The basic syntax is pretty simple. This little snippet of XAML sets the &lt;code&gt;Text&lt;/code&gt; property of the &lt;code&gt;TextBlock&lt;/code&gt; to whatever the value of the &lt;code&gt;LocalTime&lt;/code&gt; property is.&lt;br /&gt;
The curlies inside the attribute tell the XAML parser there's some magic code inside. &lt;code&gt;Binding&lt;/code&gt; is one of the keywords. Where did the &lt;code&gt;LocalTime&lt;/code&gt; property come from? Enter the &lt;code&gt;DataContext&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;Setting and Changing the DataContext&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;DataContext&lt;/code&gt; is the name of the control's (page's) property for the source of the data. This little application: &lt;/p&gt;
&lt;iframe style="WIDTH: 500px; HEIGHT: 400px" src="http://silverlight.services.live.com/invoke/74044/LocalTime/iframe.html" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;
&lt;p&gt;consists of an un-named &lt;code&gt;TextBlock&lt;/code&gt; and a button called the &lt;code&gt;announceTimeButton&lt;/code&gt;. The &lt;code&gt;DataContext&lt;/code&gt; is set in two places; the constructor and in the button's event handler. &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://www.jeffkwak.com/blog/postImages/basic-databinding-in-XAML-with-silverlight/setting-datacontext.png" /&gt; &lt;/p&gt;
&lt;p&gt;The &lt;code&gt;LocalInformation&lt;/code&gt; class is a little class which serves as this application's "ViewModel" (i.e., the thing you bind your XAML controls to). For reference, here's the source for that class: &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://www.jeffkwak.com/blog/postImages/basic-databinding-in-XAML-with-silverlight/LocalInformation.png" /&gt; &lt;/p&gt;
&lt;p&gt;What if you didn't want to new up a different instance for some reason? What if the &lt;code&gt;LocalInformation&lt;/code&gt; class was expensive to construct, or if, gosh darn it, you were just tickled &lt;br /&gt;
to be programming in a statefull environment again. Enter &lt;code&gt;INotifyPropertyChanged&lt;/code&gt; &lt;/p&gt;
&lt;h3&gt;Implement &lt;code&gt;INotifyPropertyChanged&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;I'll change the page's code to use a statefull instance of the &lt;code&gt;LocalInformation&lt;/code&gt; class. I'll set the &lt;code&gt;DataContext&lt;/code&gt; initially in the constructor, but leave it alone after that. Don't worry the binding &lt;br /&gt;
defined in the XAML will stick. &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://www.jeffkwak.com/blog/postImages/basic-databinding-in-XAML-with-silverlight/statefull-LocalInformation.png" /&gt; &lt;/p&gt;
&lt;p&gt;When the &lt;code&gt;announceTimeButton&lt;/code&gt; is clicked the &lt;code&gt;LocalInformation&lt;/code&gt; object will be tickled, and the magic that comes from having your "ViewModel" implement the &lt;code&gt;INotifyPropertyChanged&lt;/code&gt; interface will kick into action. All elements bound to the affected properties will be, ummmm...re-bound? Notice the special new &lt;code&gt;UpdateLocalTime&lt;/code&gt; method: &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://www.jeffkwak.com/blog/postImages/basic-databinding-in-XAML-with-silverlight/updatelocaltime.png" /&gt; &lt;/p&gt;
&lt;p&gt;For the purpose of this example, I put the firing of the &lt;code&gt;PropertyChanged&lt;/code&gt; event inside this method. Most of the time you'll see this refactored into it's own method so that all the properties of the class can take advantage it. The name of the property that is being updated is passed through the &lt;code&gt;PropertyChangedEventArgs&lt;/code&gt;. The only other important change to our &lt;code&gt;LocalInformation&lt;/code&gt; class is the addition of the interface itself, which forces the edition of the &lt;code&gt;PropertyChanged&lt;/code&gt; event. &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://www.jeffkwak.com/blog/postImages/basic-databinding-in-XAML-with-silverlight/INotifyPropertyChanged.png" /&gt; &lt;/p&gt;
&lt;h3&gt;Automatic Updates&lt;/h3&gt;
&lt;p&gt;So, what if you wanted some thread or timer to update the local time automatically. After all, pushing that button is awfully tedious. I know what you're thinking, you'll make some sort of "timer", and on it's callback you'll call &lt;code&gt;UpdateLocalTime&lt;/code&gt;. Well, you're close. A plain old timer will work, you just have to be carefull that the call to fire the &lt;code&gt;PropertyChanged&lt;/code&gt; event makes it back on to the same thread that's running the UI (like good ol' WinForms). This is completely possible with a class called the &lt;code&gt;Dispatcher&lt;/code&gt;, so if you wanted to but it in your model, you'd need to pass it in or get it...yadda, yadda, yadda. &lt;/p&gt;
&lt;p&gt;Luckily, this common scenario is all encapsulated by another class called the &lt;code&gt;DispatcherTimer&lt;/code&gt; (clever name isn't it). I'll make this part of my view model and initialize it in the constructor. &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://www.jeffkwak.com/blog/postImages/basic-databinding-in-XAML-with-silverlight/init-timer.png" /&gt; &lt;/p&gt;
&lt;p&gt;Then I'll add the tick handler and public methods to start and stop the timer. &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://www.jeffkwak.com/blog/postImages/basic-databinding-in-XAML-with-silverlight/timer-tick.png" /&gt; &lt;/p&gt;
&lt;p&gt;Notice the smooth databinding in the following application: &lt;/p&gt;
&lt;iframe style="WIDTH: 500px; HEIGHT: 400px" src="http://silverlight.services.live.com/invoke/74044/LocalTimeWithTimer/iframe.html" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;
&lt;p&gt;The point here is that the property update won't be seen unless it happens on the UI's thread. &lt;/p&gt;
&lt;h3&gt;Magical Databinding&lt;/h3&gt;
&lt;p&gt;There's a lot not covered here. It's just the basics as I've learned them. We didn't talk about the binding mode or dependency properties or a thousand other things that come into play when building a Silverlight UI out of XAML. In Silverlight, there are definitely more than one way to do just about anything. Databinding in general is one of the cornerstone concepts around WPF and Silverlight. &lt;/p&gt;&lt;img src="http://jeffkwak.com/blog/aggbug/31.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/DropInTheBucket/~4/jBGeXERD9EA" height="1" width="1"/&gt;</description>
            <dc:creator>Jeff Kwak</dc:creator>
            <guid isPermaLink="false">http://jeffkwak.com/blog/archive/2008/08/08/basic-databinding-in-xaml-with-silverlight.aspx</guid>
            <pubDate>Fri, 08 Aug 2008 04:18:24 GMT</pubDate>
            <comments>http://jeffkwak.com/blog/archive/2008/08/08/basic-databinding-in-xaml-with-silverlight.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://jeffkwak.com/blog/comments/commentRss/31.aspx</wfw:commentRss>
            <trackback:ping>http://jeffkwak.com/blog/services/trackbacks/31.aspx</trackback:ping>
        <feedburner:origLink>http://jeffkwak.com/blog/archive/2008/08/08/basic-databinding-in-xaml-with-silverlight.aspx</feedburner:origLink></item>
        <item>
            <title>Positioning Dynamically Created User Controls in Silverlight</title>
            <category>Silverlight</category>
            <link>http://feedproxy.google.com/~r/DropInTheBucket/~3/pn_PpMBuPB0/positioning-dynamically-created-user-controls-in-silverlight.aspx</link>
            <description>&lt;p&gt; &lt;span style="font-style: italic;"&gt;Note: This app was created using Silverlight 2.0 Beta 2&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;h3&gt;Help Me. I See Spots&lt;/h3&gt;
&lt;p&gt; Something you'll hear over and over again about Avalon (WPF) and Silverlight is how different it is when compared with more established UI platforms: like WinForms, HTML, ASP.NET, etc... I came face to face with this when I wanted to write a little spike that placed a dynamically generated user control wherever I clicked the mouse. Here's a screenshot of the application in all it's splendor: &lt;/p&gt;
&lt;img alt="screenshot" src="http://www.jeffkwak.com/blog/postImages/positioning-dynamic-silverlight-controls/finished-app.png" /&gt;

&lt;p&gt;Wait a minute! Go ahead and try it out in the little blue area below.&lt;/p&gt;

&lt;div&gt;
&lt;iframe src="http://silverlight.services.live.com/invoke/74044/DynamicPosition/iframe.html" scrolling="no" frameborder="0" style="width:400px; height:300px"&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;h3&gt;How This Works&lt;/h3&gt;
&lt;p&gt; The page is really simple. &lt;/p&gt;
&lt;img alt="page" src="http://www.jeffkwak.com/blog/postImages/positioning-dynamic-silverlight-controls/page-xaml.png" /&gt;
&lt;p&gt; Notice that it doesn't contain any elements other than the &lt;code&gt;TextBlock&lt;/code&gt; with the instructions. The &lt;code&gt;Canvas&lt;/code&gt; element ties the &lt;code&gt;MouseLeftButtonUp&lt;/code&gt; event to an appropriately named event handler which will serve as our click event. &lt;/p&gt;
&lt;p&gt; Next is the XAML markup for the "ball". This is the user control that we'll create dynamically. &lt;/p&gt;
&lt;img alt="ball" src="http://www.jeffkwak.com/blog/postImages/positioning-dynamic-silverlight-controls/ball-xaml.png" /&gt;
&lt;p&gt; The &lt;code&gt;Width&lt;/code&gt; and &lt;code&gt;Height&lt;/code&gt; are "intentionally left blank" because we're going to dynamically set the size of the ball as well as it's position. &lt;/p&gt;
&lt;p&gt; Positioning the user control is the tricky part. If you were declaring the user control in the page's XAML, you could simply use the attached properties of &lt;code&gt;Canvas.Top&lt;/code&gt; and &lt;code&gt;Canvas.Left&lt;/code&gt;. The trouble with the dynamic control, is that in the code behind there are no positioning properties like you might expect (X, Y, Left, and Top), and the attached properties are nowhere to be found. &lt;/p&gt;
&lt;p&gt; My solution was to supply the control with a render transformation. Specifically, I tie a &lt;code&gt;TranslateTransform&lt;/code&gt; at construction time. I explose an &lt;code&gt;X&lt;/code&gt; and &lt;code&gt;Y&lt;/code&gt; property on the control itself, and alter the transform in the setters. &lt;/p&gt;
&lt;div style="border: 1px solid rgb(255, 255, 0); padding: 0.3em; background: rgb(26, 24, 21) none repeat scroll 0% 50%; font-family: Consolas,'Courier New'; font-size: 10pt; color: rgb(222, 222, 203); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 1em; width: 500px;"&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   15&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;partial&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;class&lt;/span&gt; &lt;span style="color: rgb(121, 151, 84);"&gt;Ball&lt;/span&gt; : &lt;span style="color: rgb(121, 151, 84);"&gt;UserControl&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   16&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   17&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   18&lt;/span&gt;     &lt;span style="color: rgb(91, 105, 106);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;const&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;double&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;DefaultRadius&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;=&lt;/span&gt; &lt;span style="color: rgb(140, 112, 80);"&gt;25.0&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   19&lt;/span&gt;     &lt;span style="color: rgb(91, 105, 106);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;const&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;double&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;DefaultX&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;=&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;DefaultRadius&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   20&lt;/span&gt;     &lt;span style="color: rgb(91, 105, 106);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;const&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;double&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;DefaultY&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;=&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;DefaultRadius&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   21&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   22&lt;/span&gt;     &lt;span style="color: rgb(91, 105, 106);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;double&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;_x&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   23&lt;/span&gt;     &lt;span style="color: rgb(91, 105, 106);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;double&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;_y&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   24&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   25&lt;/span&gt;     &lt;span style="color: rgb(91, 105, 106);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(121, 151, 84);"&gt;TranslateTransform&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;_translation&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;=&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   26&lt;/span&gt;         &lt;span style="color: rgb(91, 105, 106);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(121, 151, 84);"&gt;TranslateTransform&lt;/span&gt;();&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   27&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   28&lt;/span&gt;     &lt;span style="color: rgb(91, 105, 106);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;double&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;X&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   29&lt;/span&gt;     {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   30&lt;/span&gt;         &lt;span style="color: rgb(91, 105, 106);"&gt;get&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   31&lt;/span&gt;         {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   32&lt;/span&gt;             &lt;span style="color: rgb(91, 105, 106);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;_x&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   33&lt;/span&gt;         }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   34&lt;/span&gt;         &lt;span style="color: rgb(91, 105, 106);"&gt;set&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   35&lt;/span&gt;         {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   36&lt;/span&gt;             &lt;span style="color: rgb(199, 199, 165);"&gt;_x&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;=&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;value&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   37&lt;/span&gt;             &lt;span style="color: rgb(199, 199, 165);"&gt;_translation&lt;/span&gt;&lt;span style="color: rgb(150, 120, 120);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(199, 199, 165);"&gt;X&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;=&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;_x&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;-&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;Radius&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   38&lt;/span&gt;         }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   39&lt;/span&gt;     }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   40&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   41&lt;/span&gt;     &lt;span style="color: rgb(91, 105, 106);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;double&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;Y&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   42&lt;/span&gt;     {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   43&lt;/span&gt;         &lt;span style="color: rgb(91, 105, 106);"&gt;get&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   44&lt;/span&gt;         {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   45&lt;/span&gt;             &lt;span style="color: rgb(91, 105, 106);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;_y&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   46&lt;/span&gt;         }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   47&lt;/span&gt;         &lt;span style="color: rgb(91, 105, 106);"&gt;set&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   48&lt;/span&gt;         {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   49&lt;/span&gt;             &lt;span style="color: rgb(199, 199, 165);"&gt;_y&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;=&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;value&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   50&lt;/span&gt;             &lt;span style="color: rgb(199, 199, 165);"&gt;_translation&lt;/span&gt;&lt;span style="color: rgb(150, 120, 120);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(199, 199, 165);"&gt;Y&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;=&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;value&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;-&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;Radius&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   51&lt;/span&gt;         }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   52&lt;/span&gt;     }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   53&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   54&lt;/span&gt;     &lt;span style="color: rgb(91, 105, 106);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;double&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;Radius&lt;/span&gt; { &lt;span style="color: rgb(91, 105, 106);"&gt;get&lt;/span&gt;; &lt;span style="color: rgb(91, 105, 106);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;set&lt;/span&gt;; }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   55&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   56&lt;/span&gt;     &lt;span style="color: rgb(91, 105, 106);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;Ball&lt;/span&gt;() : &lt;span style="color: rgb(91, 105, 106);"&gt;this&lt;/span&gt;(&lt;span style="color: rgb(199, 199, 165);"&gt;DefaultRadius&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   57&lt;/span&gt;     {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   58&lt;/span&gt;     }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   59&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   60&lt;/span&gt;     &lt;span style="color: rgb(91, 105, 106);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;Ball&lt;/span&gt;(&lt;span style="color: rgb(91, 105, 106);"&gt;double&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;r&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   61&lt;/span&gt;     {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   62&lt;/span&gt;         &lt;span style="color: rgb(199, 199, 165);"&gt;validateConstructor&lt;/span&gt;(&lt;span style="color: rgb(199, 199, 165);"&gt;r&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   63&lt;/span&gt;         &lt;span style="color: rgb(199, 199, 165);"&gt;Radius&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;=&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;r&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   64&lt;/span&gt;         &lt;span style="color: rgb(199, 199, 165);"&gt;Width&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;=&lt;/span&gt; &lt;span style="color: rgb(140, 112, 80);"&gt;2&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;*&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;r&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   65&lt;/span&gt;         &lt;span style="color: rgb(199, 199, 165);"&gt;Height&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;=&lt;/span&gt; &lt;span style="color: rgb(140, 112, 80);"&gt;2&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;*&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;r&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   66&lt;/span&gt;         &lt;span style="color: rgb(199, 199, 165);"&gt;RenderTransform&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;=&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;_translation&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   67&lt;/span&gt;         &lt;span style="color: rgb(199, 199, 165);"&gt;InitializeComponent&lt;/span&gt;();&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   68&lt;/span&gt;     }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   69&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   70&lt;/span&gt;     &lt;span style="color: rgb(91, 105, 106);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;void&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;validateConstructor&lt;/span&gt;(&lt;span style="color: rgb(91, 105, 106);"&gt;double&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;r&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   71&lt;/span&gt;     {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   72&lt;/span&gt;         &lt;span style="color: rgb(91, 105, 106);"&gt;if&lt;/span&gt;(&lt;span style="color: rgb(199, 199, 165);"&gt;r&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;&amp;lt;=&lt;/span&gt; &lt;span style="color: rgb(140, 112, 80);"&gt;0.0&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   73&lt;/span&gt;         {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   74&lt;/span&gt;             &lt;span style="color: rgb(91, 105, 106);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(121, 151, 84);"&gt;ArgumentException&lt;/span&gt;(&lt;span style="color: rgb(140, 112, 80); font-weight: bold;"&gt;"Please provide...&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   75&lt;/span&gt;         }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   76&lt;/span&gt;     }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   77&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; The page simply news up a &lt;code&gt;Ball&lt;/code&gt; and sets the x and y according to the mouse click. &lt;/p&gt;
&lt;div style="border: 1px solid rgb(255, 255, 0); padding: 0.3em; background: rgb(26, 24, 21) none repeat scroll 0% 50%; font-family: Consolas,'Courier New'; font-size: 10pt; color: rgb(222, 222, 203); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 1em; width: 500px;"&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   21&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   22&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;void&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;LayoutRoot_MouseLeftButtonUp&lt;/span&gt;(&lt;span style="color: rgb(91, 105, 106);"&gt;object&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;sender&lt;/span&gt;, ...&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   23&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   24&lt;/span&gt;     &lt;span style="color: rgb(166, 92, 92);"&gt;Point&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;clickPoint&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;=&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;e&lt;/span&gt;&lt;span style="color: rgb(150, 120, 120);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(199, 199, 165);"&gt;GetPosition&lt;/span&gt;(&lt;span style="color: rgb(199, 199, 165);"&gt;LayoutRoot&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   25&lt;/span&gt;     &lt;span style="color: rgb(121, 151, 84);"&gt;Ball&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;b&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;=&lt;/span&gt; &lt;span style="color: rgb(91, 105, 106);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(121, 151, 84);"&gt;Ball&lt;/span&gt;( );&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   26&lt;/span&gt;     &lt;span style="color: rgb(199, 199, 165);"&gt;b&lt;/span&gt;&lt;span style="color: rgb(150, 120, 120);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(199, 199, 165);"&gt;X&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;=&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;clickPoint&lt;/span&gt;&lt;span style="color: rgb(150, 120, 120);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(199, 199, 165);"&gt;X&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   27&lt;/span&gt;     &lt;span style="color: rgb(199, 199, 165);"&gt;b&lt;/span&gt;&lt;span style="color: rgb(150, 120, 120);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(199, 199, 165);"&gt;Y&lt;/span&gt; &lt;span style="color: rgb(150, 120, 120);"&gt;=&lt;/span&gt; &lt;span style="color: rgb(199, 199, 165);"&gt;clickPoint&lt;/span&gt;&lt;span style="color: rgb(150, 120, 120);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(199, 199, 165);"&gt;Y&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   28&lt;/span&gt;     &lt;span style="color: rgb(199, 199, 165);"&gt;LayoutRoot&lt;/span&gt;&lt;span style="color: rgb(150, 120, 120);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(199, 199, 165);"&gt;Children&lt;/span&gt;&lt;span style="color: rgb(150, 120, 120);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(199, 199, 165);"&gt;Add&lt;/span&gt;(&lt;span style="color: rgb(199, 199, 165);"&gt;b&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   29&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="background: rgb(46, 44, 38) none repeat scroll 0% 50%; color: rgb(91, 105, 106); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   30&lt;/span&gt; &lt;/pre&gt;
&lt;/div&gt;
&lt;a href="http://www.jeffkwak.com/blog/postAttachments/PositionDynamicUserControls.zip"&gt;Download the Code&lt;/a&gt;&lt;img src="http://jeffkwak.com/blog/aggbug/30.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/DropInTheBucket/~4/pn_PpMBuPB0" height="1" width="1"/&gt;</description>
            <dc:creator>Jeff Kwak</dc:creator>
            <guid isPermaLink="false">http://jeffkwak.com/blog/archive/2008/07/29/positioning-dynamically-created-user-controls-in-silverlight.aspx</guid>
            <pubDate>Tue, 29 Jul 2008 04:52:23 GMT</pubDate>
            <comments>http://jeffkwak.com/blog/archive/2008/07/29/positioning-dynamically-created-user-controls-in-silverlight.aspx#feedback</comments>
            <wfw:commentRss>http://jeffkwak.com/blog/comments/commentRss/30.aspx</wfw:commentRss>
            <trackback:ping>http://jeffkwak.com/blog/services/trackbacks/30.aspx</trackback:ping>
        <feedburner:origLink>http://jeffkwak.com/blog/archive/2008/07/29/positioning-dynamically-created-user-controls-in-silverlight.aspx</feedburner:origLink></item>
        <item>
            <title>ASP.NET MVC Preview 4: A few things left to do</title>
            <category>MVC</category>
            <link>http://feedproxy.google.com/~r/DropInTheBucket/~3/4XNFodbfLF0/asp.net-mvc-preview-4-a-few-things-left-to-do.aspx</link>
            <description>&lt;p&gt;
I decided, I'd try out Preview 4 tonight. In honest to goodness TDD form, I wrote the following test:
&lt;/p&gt;
&lt;div style="font-family: Consolas, 'Courier New'; font-size: 10pt; color: #dedecb; background: #1a1815; line-height: 1em; width: 500px; padding: 0.3em; border: solid 1px #FF0;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   13&lt;/span&gt; [&lt;span style="color: #799754;"&gt;TestFixture&lt;/span&gt;]&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   14&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;public&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;class&lt;/span&gt; &lt;span style="color: #799754;"&gt;EmployeeControllerTests&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   15&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   16&lt;/span&gt;     [&lt;span style="color: #799754;"&gt;Test&lt;/span&gt;]&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   17&lt;/span&gt;     &lt;span style="color: #5b696a;"&gt;public&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;void&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;List_Should_Render_View_Of_Employees&lt;/span&gt;()&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   18&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   19&lt;/span&gt;         &lt;span style="color: #5b696a;"&gt;var&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;controller&lt;/span&gt; &lt;span style="color: #967878;"&gt;=&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;new&lt;/span&gt; &lt;span style="color: #799754;"&gt;EmployeeController&lt;/span&gt;();&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   20&lt;/span&gt;         &lt;span style="color: #5b696a;"&gt;var&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;result&lt;/span&gt; &lt;span style="color: #967878;"&gt;=&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;controller&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;List&lt;/span&gt;() &lt;span style="color: #5b696a;"&gt;as&lt;/span&gt; &lt;span style="color: #799754;"&gt;ViewResult&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   21&lt;/span&gt;         &lt;span style="color: #799754;"&gt;Assert&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;IsNotNull&lt;/span&gt;(&lt;span style="color: #c7c7a5;"&gt;result&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   22&lt;/span&gt;         &lt;span style="color: #799754;"&gt;Assert&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;AreEqual&lt;/span&gt;(&lt;span style="color: #8c7050; font-weight: bold;"&gt;"List"&lt;/span&gt;, &lt;span style="color: #c7c7a5;"&gt;result&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;ViewName&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   23&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   24&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
The code for the controller is:
&lt;/p&gt;
&lt;div style="font-family: Consolas, 'Courier New'; font-size: 10pt; color: #dedecb; background: #1a1815; line-height: 1em; width: 500px; padding: 0.3em; border: solid 1px #FF0;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;    9&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;public&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;class&lt;/span&gt; &lt;span style="color: #799754;"&gt;EmployeeController&lt;/span&gt; : &lt;span style="color: #799754;"&gt;Controller&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   10&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   11&lt;/span&gt;     &lt;span style="color: #5b696a;"&gt;public&lt;/span&gt; &lt;span style="color: #799754;"&gt;ActionResult&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;List&lt;/span&gt;()&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   12&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   13&lt;/span&gt;         &lt;span style="color: #5b696a;"&gt;return&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;View&lt;/span&gt;();&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   14&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   15&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
The test fails. The name of the view is null &lt;i&gt;(assertion on line 22 of the test method)&lt;/i&gt;. Why in the name of all that is ScottGu would this basic test fail? In the actual view, when rendered through the view engine, the view name is "List" as expected (that's the job of the parameter-less call to the controller's &lt;code&gt;View&lt;/code&gt; method). 
&lt;/p&gt;
&lt;p&gt;
Testing of the controller in isolation is still not fully baked. There still seems to be some disconnect in one of the fundamental goals of the framework: make it easy for Morts like me to write testable code.
&lt;/p&gt;
&lt;img src="http://jeffkwak.com/blog/aggbug/29.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/DropInTheBucket/~4/4XNFodbfLF0" height="1" width="1"/&gt;</description>
            <dc:creator>Jeff Kwak</dc:creator>
            <guid isPermaLink="false">http://jeffkwak.com/blog/archive/2008/07/22/asp.net-mvc-preview-4-a-few-things-left-to-do.aspx</guid>
            <pubDate>Wed, 23 Jul 2008 03:50:31 GMT</pubDate>
            <comments>http://jeffkwak.com/blog/archive/2008/07/22/asp.net-mvc-preview-4-a-few-things-left-to-do.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://jeffkwak.com/blog/comments/commentRss/29.aspx</wfw:commentRss>
            <trackback:ping>http://jeffkwak.com/blog/services/trackbacks/29.aspx</trackback:ping>
        <feedburner:origLink>http://jeffkwak.com/blog/archive/2008/07/22/asp.net-mvc-preview-4-a-few-things-left-to-do.aspx</feedburner:origLink></item>
        <item>
            <title>Please Read the Error Message</title>
            <category>General</category>
            <link>http://feedproxy.google.com/~r/DropInTheBucket/~3/Di5jIs3TdHQ/please-read-the-error-message.aspx</link>
            <description>&lt;h2&gt;Generic List Doesn’t Support the Query Pattern&lt;/h2&gt;
&lt;p&gt;I recently wrote similar code to this little fragment (this is a sanitized version for the purpose of this example).&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="BORDER-RIGHT: #ff0 1px solid; PADDING-RIGHT: 0.5em; BORDER-TOP: #ff0 1px solid; PADDING-LEFT: 0.5em; FONT-SIZE: 10pt; BACKGROUND: black; PADDING-BOTTOM: 0.5em; BORDER-LEFT: #ff0 1px solid; WIDTH: 400px; COLOR: white; LINE-HEIGHT: 1em; PADDING-TOP: 0.5em; BORDER-BOTTOM: #ff0 1px solid; FONT-FAMILY: Consolas, 'Courier New'"&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: #2b91af"&gt;   12&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: #2b91af"&gt;   13&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #f47a00"&gt;int&lt;/span&gt;&amp;gt; &lt;span style="COLOR: #fddf39"&gt;nums&lt;/span&gt; = &lt;span style="COLOR: #f47a00"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #f47a00"&gt;int&lt;/span&gt;&amp;gt; { &lt;span style="COLOR: yellow"&gt;0&lt;/span&gt;, &lt;span style="COLOR: yellow"&gt;1&lt;/span&gt;, &lt;span style="COLOR: yellow"&gt;1&lt;/span&gt;, &lt;span style="COLOR: yellow"&gt;2&lt;/span&gt;,&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: #2b91af"&gt;   14&lt;/span&gt;                     &lt;span style="COLOR: yellow"&gt;3&lt;/span&gt;, &lt;span style="COLOR: yellow"&gt;5&lt;/span&gt;, &lt;span style="COLOR: yellow"&gt;8&lt;/span&gt;, &lt;span style="COLOR: yellow"&gt;13&lt;/span&gt;, &lt;span style="COLOR: yellow"&gt;21&lt;/span&gt; };&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: #2b91af"&gt;   15&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: #2b91af"&gt;   16&lt;/span&gt; &lt;span style="COLOR: #f47a00"&gt;var&lt;/span&gt; &lt;span style="COLOR: #fddf39"&gt;evenQ&lt;/span&gt; = &lt;span style="COLOR: #f47a00"&gt;from&lt;/span&gt; &lt;span style="COLOR: #fddf39"&gt;n&lt;/span&gt; &lt;span style="COLOR: #f47a00"&gt;in&lt;/span&gt; &lt;span style="COLOR: #fddf39"&gt;nums&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: #2b91af"&gt;   17&lt;/span&gt;             &lt;span style="COLOR: #f47a00"&gt;where&lt;/span&gt; &lt;span style="COLOR: #fddf39"&gt;n&lt;/span&gt; % &lt;span style="COLOR: yellow"&gt;2&lt;/span&gt; == &lt;span style="COLOR: yellow"&gt;0&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: #2b91af"&gt;   18&lt;/span&gt;             &lt;span style="COLOR: #f47a00"&gt;select&lt;/span&gt; &lt;span style="COLOR: #fddf39"&gt;n&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: #2b91af"&gt;   19&lt;/span&gt; &lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;I was shocked when I received this error message&lt;/p&gt;
&lt;p&gt;&lt;img height="110" alt="" width="682" src="http://www.jeffkwak.com/blog/postImages/plesae-read-the-error-message/compiler-error.png" /&gt;&lt;/p&gt;
&lt;p&gt;WTF! What do you mean, a list doesn’t support the query pattern!? That’s absolutely ridiculous. I’m quiting C# development, and I’m converting to writing Rails apps on the Mac….&lt;/p&gt;
&lt;div style="PADDING-RIGHT: 2em; PADDING-LEFT: 2em; PADDING-BOTTOM: 2em; WIDTH: 345px; PADDING-TOP: 2em; BACKGROUND-COLOR: #ffa"&gt;
&lt;p style="FONT-WEIGHT: bold"&gt;We interrupt this moment of panic for the following public service announcement:&lt;/p&gt;
&lt;p&gt;Developers, do you get tired of reading those pesky error messages? Me too, but remember the compiler team has gone through a lot of trouble to tell you when you’re an idiot and help you recover. Take it from me, if you read the entire error me sage instead of the first half sentence, you’ll be better informed of why you’re such a bonehead and more likely to recover. Now back to our regularly scheduled moment of sanity.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;...”missing &lt;snip&gt;&lt;/snip&gt;a using directive?”. Yes, as it turns out I prematurely used one of my favorite VS features: remove and sort using statements.&lt;/p&gt;
&lt;p&gt;&lt;img height="456" alt="" width="329" src="http://www.jeffkwak.com/blog/postImages/plesae-read-the-error-message/remove-and-sort.png" /&gt;&lt;/p&gt;
&lt;p&gt;All is well, and the universe is in a causal state again. Turns out that if you don’t have any dependencies on statements or extensions in &lt;code&gt;System.Linq&lt;/code&gt; “remove and sort” will remove the LINQ using statement (duh), and thus all the LINQ goodness will be hidden from the compiler.&lt;/p&gt;
&lt;p&gt;Simply adding &lt;code&gt;using System.Linq;&lt;/code&gt; fixed this particular goof. Yes, perhaps I’ll read the entire error message next time.&lt;/p&gt;&lt;img src="http://jeffkwak.com/blog/aggbug/28.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/DropInTheBucket/~4/Di5jIs3TdHQ" height="1" width="1"/&gt;</description>
            <dc:creator>Jeff Kwak</dc:creator>
            <guid isPermaLink="false">http://jeffkwak.com/blog/archive/2008/05/29/please-read-the-error-message.aspx</guid>
            <pubDate>Fri, 30 May 2008 03:15:04 GMT</pubDate>
            <comments>http://jeffkwak.com/blog/archive/2008/05/29/please-read-the-error-message.aspx#feedback</comments>
            <wfw:commentRss>http://jeffkwak.com/blog/comments/commentRss/28.aspx</wfw:commentRss>
            <trackback:ping>http://jeffkwak.com/blog/services/trackbacks/28.aspx</trackback:ping>
        <feedburner:origLink>http://jeffkwak.com/blog/archive/2008/05/29/please-read-the-error-message.aspx</feedburner:origLink></item>
        <item>
            <title>Goodbye Motorola</title>
            <category>General</category>
            <link>http://feedproxy.google.com/~r/DropInTheBucket/~3/pup0q-mqk58/goodbye-motorola.aspx</link>
            <description>&lt;h2&gt;The Post I Should Never Have Written&lt;/h2&gt;
&lt;p&gt;I spent the entire month of April, writting and re-writting this post. You see, I used to work for Motorola. As a matter of fact, all combined I worked for them for a total of nearly 13 years. Some of my original drafts blasted middle management, upper management, CEOs, and pointed out all that was wrong with the company. &lt;/p&gt;
&lt;p&gt;I finally decided to shelve the burn Motorola post. Motorola is burning by itself without any additional help from me. I will say one thing, the one thing that I feel doomed Motorola, more than any of its problems with management: Motorola forgot that it survived by providing a place for people to innovate. The company started treating everyone like an interchangeable commodity. The company turned its back on being loyal towards its people, and as a result the company lost the loyality of its people—mainly through fear. The end result was the company cutting its own lifeline: innovation.&lt;/p&gt;&lt;img src="http://jeffkwak.com/blog/aggbug/27.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/DropInTheBucket/~4/pup0q-mqk58" height="1" width="1"/&gt;</description>
            <dc:creator>Jeff Kwak</dc:creator>
            <guid isPermaLink="false">http://jeffkwak.com/blog/archive/2008/05/09/goodbye-motorola.aspx</guid>
            <pubDate>Fri, 09 May 2008 04:48:39 GMT</pubDate>
            <comments>http://jeffkwak.com/blog/archive/2008/05/09/goodbye-motorola.aspx#feedback</comments>
            <wfw:commentRss>http://jeffkwak.com/blog/comments/commentRss/27.aspx</wfw:commentRss>
            <trackback:ping>http://jeffkwak.com/blog/services/trackbacks/27.aspx</trackback:ping>
        <feedburner:origLink>http://jeffkwak.com/blog/archive/2008/05/09/goodbye-motorola.aspx</feedburner:origLink></item>
        <item>
            <title>Refactoring the Sieve of Eratosthenes</title>
            <category>LINQ</category>
            <link>http://feedproxy.google.com/~r/DropInTheBucket/~3/e4xOz7EAIYU/refactoring-the-sieve-of-eratosthenes.aspx</link>
            <description>I have recently been reading "Agile Principles, Patterns, and Practices in C#" by Robert C Martin and Micah Martin. So far, it's been an enjoyable read. Early on the authors explain the concept of refactoring by showing how they would go about refactoring the "Sieve of Eratosthenes":http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes. The algorithm is a way to generate a list of prime numbers.  The final refactored solution is full of loops and breaks, which is fine, but like most things -- it looked like a job for LINQ! I decided to repeat the exercise using as much LINQ as I could reasonably stuff into algorithm. Here is my green pass (of a red-green-refactor cycle).
&lt;div style="border: 1px solid rgb(255, 255, 0); padding: 0.5em; background: black none repeat scroll 0% 50%; font-family: Consolas,'Courier New'; font-size: 10pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 1em; width: 600px;"&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   18&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   19&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt;&amp;gt; &lt;span style="color: rgb(253, 223, 57);"&gt;GenerateListOfPrimes&lt;/span&gt;(&lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;maxNumber&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   20&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   21&lt;/span&gt;     &lt;span style="color: rgb(43, 145, 175);"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt;&amp;gt; &lt;span style="color: rgb(253, 223, 57);"&gt;result&lt;/span&gt; = &lt;span style="color: rgb(244, 122, 0);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt;&amp;gt;();&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   22&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   23&lt;/span&gt;     &lt;span style="color: rgb(244, 122, 0);"&gt;if&lt;/span&gt; (&lt;span style="color: rgb(253, 223, 57);"&gt;maxNumber&lt;/span&gt; &amp;gt; &lt;span style="color: yellow;"&gt;1&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   24&lt;/span&gt;     {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   25&lt;/span&gt;         &lt;span style="color: rgb(244, 122, 0);"&gt;var&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;candidateNumbers&lt;/span&gt; =&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   26&lt;/span&gt;           &lt;span style="color: rgb(43, 145, 175);"&gt;Enumerable&lt;/span&gt;.&lt;span style="color: rgb(253, 223, 57);"&gt;Range&lt;/span&gt;(&lt;span style="color: yellow;"&gt;2&lt;/span&gt;, &lt;span style="color: rgb(253, 223, 57);"&gt;maxNumber&lt;/span&gt; - &lt;span style="color: yellow;"&gt;1&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   27&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   28&lt;/span&gt;         &lt;span style="color: rgb(244, 122, 0);"&gt;double&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;stopNumber&lt;/span&gt; = &lt;span style="color: rgb(253, 223, 57);"&gt;System&lt;/span&gt;.&lt;span style="color: rgb(43, 145, 175);"&gt;Math&lt;/span&gt;.&lt;span style="color: rgb(253, 223, 57);"&gt;Sqrt&lt;/span&gt;(&lt;span style="color: rgb(253, 223, 57);"&gt;maxNumber&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   29&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   30&lt;/span&gt;         &lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;nextPrime&lt;/span&gt; = &lt;span style="color: yellow;"&gt;2&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   31&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   32&lt;/span&gt;         &lt;span style="color: rgb(244, 122, 0);"&gt;while&lt;/span&gt; (&lt;span style="color: rgb(253, 223, 57);"&gt;nextPrime&lt;/span&gt; &amp;lt;= &lt;span style="color: rgb(253, 223, 57);"&gt;stopNumber&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   33&lt;/span&gt;         {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   34&lt;/span&gt;             &lt;span style="color: rgb(253, 223, 57);"&gt;candidateNumbers&lt;/span&gt; =&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   35&lt;/span&gt;             (&lt;span style="color: rgb(244, 122, 0);"&gt;from&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;n&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;candidateNumbers&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   36&lt;/span&gt;             &lt;span style="color: rgb(244, 122, 0);"&gt;where&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   37&lt;/span&gt;               &lt;span style="color: rgb(253, 223, 57);"&gt;n&lt;/span&gt; &amp;lt;= &lt;span style="color: rgb(253, 223, 57);"&gt;nextPrime&lt;/span&gt; ||&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   38&lt;/span&gt;               &lt;span style="color: rgb(253, 223, 57);"&gt;n&lt;/span&gt; % &lt;span style="color: rgb(253, 223, 57);"&gt;nextPrime&lt;/span&gt; != &lt;span style="color: yellow;"&gt;0&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   39&lt;/span&gt;             &lt;span style="color: rgb(244, 122, 0);"&gt;select&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;n&lt;/span&gt;).&lt;span style="color: rgb(253, 223, 57);"&gt;ToList&lt;/span&gt;();&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   40&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   41&lt;/span&gt;             &lt;span style="color: rgb(253, 223, 57);"&gt;nextPrime&lt;/span&gt; =&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   42&lt;/span&gt;                (&lt;span style="color: rgb(244, 122, 0);"&gt;from&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;p&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;candidateNumbers&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   43&lt;/span&gt;                 &lt;span style="color: rgb(244, 122, 0);"&gt;where&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;p&lt;/span&gt; &amp;gt; &lt;span style="color: rgb(253, 223, 57);"&gt;nextPrime&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   44&lt;/span&gt;                 &lt;span style="color: rgb(244, 122, 0);"&gt;select&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;p&lt;/span&gt;).&lt;span style="color: rgb(253, 223, 57);"&gt;First&lt;/span&gt;();&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   45&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   46&lt;/span&gt;         }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   47&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   48&lt;/span&gt;         &lt;span style="color: rgb(253, 223, 57);"&gt;result&lt;/span&gt; = &lt;span style="color: rgb(253, 223, 57);"&gt;candidateNumbers&lt;/span&gt;.&lt;span style="color: rgb(253, 223, 57);"&gt;ToList&lt;/span&gt;();&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   49&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   50&lt;/span&gt;     }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   51&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   52&lt;/span&gt;     &lt;span style="color: rgb(244, 122, 0);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;result&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   53&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   54&lt;/span&gt; &lt;/pre&gt;
&lt;/div&gt;
Well, it uses LINQ, but it ain't lovely. I ended up refactoring the code in much the same way that the authors did. Primarily by breaking up the long method (Extract Method). The final pass of the method ended up looking like this:
&lt;div style="border: 1px solid rgb(255, 255, 0); padding: 0.5em; background: black none repeat scroll 0% 50%; font-family: Consolas,'Courier New'; font-size: 10pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 1em; width: 600px;"&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   31&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   32&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt;[] &lt;span style="color: rgb(253, 223, 57);"&gt;GeneratePrimes&lt;/span&gt;(&lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;maxNumber&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   33&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   34&lt;/span&gt;     &lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt;[] &lt;span style="color: rgb(253, 223, 57);"&gt;result&lt;/span&gt; = &lt;span style="color: rgb(244, 122, 0);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt;[] { };&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   35&lt;/span&gt;     &lt;span style="color: rgb(244, 122, 0);"&gt;if&lt;/span&gt; (&lt;span style="color: rgb(253, 223, 57);"&gt;maxNumber&lt;/span&gt; &amp;gt; &lt;span style="color: yellow;"&gt;1&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   36&lt;/span&gt;     {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   37&lt;/span&gt;         &lt;span style="color: rgb(253, 223, 57);"&gt;InitializeRangeOfNumbers&lt;/span&gt;(&lt;span style="color: rgb(253, 223, 57);"&gt;maxNumber&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   38&lt;/span&gt;         &lt;span style="color: rgb(253, 223, 57);"&gt;InitializeLastNumberToCheck&lt;/span&gt;(&lt;span style="color: rgb(253, 223, 57);"&gt;maxNumber&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   39&lt;/span&gt;         &lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;prime&lt;/span&gt; = &lt;span style="color: yellow;"&gt;2&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   40&lt;/span&gt;         &lt;span style="color: rgb(244, 122, 0);"&gt;while&lt;/span&gt; (&lt;span style="color: rgb(253, 223, 57);"&gt;RemainingNumbersContainFactorsOf&lt;/span&gt;(&lt;span style="color: rgb(253, 223, 57);"&gt;prime&lt;/span&gt;))&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   41&lt;/span&gt;         {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   42&lt;/span&gt;             &lt;span style="color: rgb(253, 223, 57);"&gt;RemoveFactorsOf&lt;/span&gt;(&lt;span style="color: rgb(253, 223, 57);"&gt;prime&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   43&lt;/span&gt;             &lt;span style="color: rgb(253, 223, 57);"&gt;prime&lt;/span&gt; = &lt;span style="color: rgb(253, 223, 57);"&gt;NextPrime&lt;/span&gt;(&lt;span style="color: rgb(253, 223, 57);"&gt;prime&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   44&lt;/span&gt;         }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   45&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   46&lt;/span&gt;         &lt;span style="color: rgb(253, 223, 57);"&gt;result&lt;/span&gt; = &lt;span style="color: rgb(253, 223, 57);"&gt;_remainingNumbers&lt;/span&gt;.&lt;span style="color: rgb(253, 223, 57);"&gt;ToArray&lt;/span&gt;();&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   47&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   48&lt;/span&gt;     }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   49&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   50&lt;/span&gt;     &lt;span style="color: rgb(244, 122, 0);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;result&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   51&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   52&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   53&lt;/span&gt; &lt;/pre&gt;
&lt;/div&gt;
The implementation of the methods look like this:
&lt;div style="border: 1px solid rgb(255, 255, 0); padding: 0.5em; background: black none repeat scroll 0% 50%; font-family: Consolas,'Courier New'; font-size: 10pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 1em; width: 600px;"&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   54&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   55&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;void&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;InitializeLastNumberToCheck&lt;/span&gt;(&lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;maxNumber&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   56&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   57&lt;/span&gt;     &lt;span style="color: rgb(253, 223, 57);"&gt;_lastNumberToCheck&lt;/span&gt; = &lt;span style="color: rgb(43, 145, 175);"&gt;Math&lt;/span&gt;.&lt;span style="color: rgb(253, 223, 57);"&gt;Sqrt&lt;/span&gt;(&lt;span style="color: rgb(253, 223, 57);"&gt;maxNumber&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   58&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   59&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   60&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;void&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;InitializeRangeOfNumbers&lt;/span&gt;(&lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;maxNumber&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   61&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   62&lt;/span&gt;     &lt;span style="color: rgb(253, 223, 57);"&gt;_remainingNumbers&lt;/span&gt; = &lt;span style="color: rgb(43, 145, 175);"&gt;Enumerable&lt;/span&gt;.&lt;span style="color: rgb(253, 223, 57);"&gt;Range&lt;/span&gt;(&lt;span style="color: yellow;"&gt;2&lt;/span&gt;, &lt;span style="color: rgb(253, 223, 57);"&gt;maxNumber&lt;/span&gt; - &lt;span style="color: yellow;"&gt;1&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   63&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   64&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   65&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;NextPrime&lt;/span&gt;(&lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;currentPrime&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   66&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   67&lt;/span&gt;     &lt;span style="color: rgb(244, 122, 0);"&gt;return&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   68&lt;/span&gt;         (&lt;span style="color: rgb(244, 122, 0);"&gt;from&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;p&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;_remainingNumbers&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   69&lt;/span&gt;          &lt;span style="color: rgb(244, 122, 0);"&gt;where&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;p&lt;/span&gt; &amp;gt; &lt;span style="color: rgb(253, 223, 57);"&gt;currentPrime&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   70&lt;/span&gt;          &lt;span style="color: rgb(244, 122, 0);"&gt;select&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;p&lt;/span&gt;).&lt;span style="color: rgb(253, 223, 57);"&gt;First&lt;/span&gt;();&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   71&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   72&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   73&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;bool&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;RemainingNumbersContainFactorsOf&lt;/span&gt;(&lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;prime&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   74&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   75&lt;/span&gt;     &lt;span style="color: rgb(244, 122, 0);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;prime&lt;/span&gt; &amp;lt;= &lt;span style="color: rgb(253, 223, 57);"&gt;_lastNumberToCheck&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   76&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   77&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   78&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;void&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;RemoveFactorsOf&lt;/span&gt;(&lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;prime&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   79&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   80&lt;/span&gt;     &lt;span style="color: rgb(253, 223, 57);"&gt;_remainingNumbers&lt;/span&gt; =&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   81&lt;/span&gt;         (&lt;span style="color: rgb(244, 122, 0);"&gt;from&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;n&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;_remainingNumbers&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   82&lt;/span&gt;          &lt;span style="color: rgb(244, 122, 0);"&gt;where&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   83&lt;/span&gt;            &lt;span style="color: rgb(253, 223, 57);"&gt;n&lt;/span&gt; &amp;lt;= &lt;span style="color: rgb(253, 223, 57);"&gt;prime&lt;/span&gt; ||&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   84&lt;/span&gt;            &lt;span style="color: rgb(253, 223, 57);"&gt;n&lt;/span&gt; % &lt;span style="color: rgb(253, 223, 57);"&gt;prime&lt;/span&gt; != &lt;span style="color: yellow;"&gt;0&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   85&lt;/span&gt;          &lt;span style="color: rgb(244, 122, 0);"&gt;select&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;n&lt;/span&gt;).&lt;span style="color: rgb(253, 223, 57);"&gt;ToList&lt;/span&gt;();&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   86&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   87&lt;/span&gt; &lt;/pre&gt;
&lt;/div&gt;
You might be interested to know that the LINQ implementation is (ever so) slightly faster than the Martin version. Both versions can compute the first 100,000 primes in less than a second. I haven't dug into the reason why.  For fun, I decided to implement an algorithm that would fall into the LINQ way a little easier. I came up with this:
&lt;div style="border: 1px solid rgb(255, 255, 0); padding: 0.5em; background: black none repeat scroll 0% 50%; font-family: Consolas,'Courier New'; font-size: 10pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 1em; width: 600px;"&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   27&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   28&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt;[] &lt;span style="color: rgb(253, 223, 57);"&gt;GeneratePrimes&lt;/span&gt;(&lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;maxNumber&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   29&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   30&lt;/span&gt;     &lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt; [] &lt;span style="color: rgb(253, 223, 57);"&gt;result&lt;/span&gt; = &lt;span style="color: rgb(244, 122, 0);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt; [] { };&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   31&lt;/span&gt;     &lt;span style="color: rgb(244, 122, 0);"&gt;if&lt;/span&gt;(&lt;span style="color: rgb(253, 223, 57);"&gt;maxNumber&lt;/span&gt; &amp;gt; &lt;span style="color: yellow;"&gt;1&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   32&lt;/span&gt;     {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   33&lt;/span&gt;         &lt;span style="color: rgb(244, 122, 0);"&gt;var&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;primeNumbers&lt;/span&gt; =&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   34&lt;/span&gt;             &lt;span style="color: rgb(244, 122, 0);"&gt;from&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;n&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Enumerable&lt;/span&gt;.&lt;span style="color: rgb(253, 223, 57);"&gt;Range&lt;/span&gt;(&lt;span style="color: yellow;"&gt;2&lt;/span&gt;, &lt;span style="color: rgb(253, 223, 57);"&gt;maxNumber&lt;/span&gt; - &lt;span style="color: yellow;"&gt;1&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   35&lt;/span&gt;             &lt;span style="color: rgb(244, 122, 0);"&gt;where&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;n&lt;/span&gt;.&lt;span style="color: rgb(253, 223, 57);"&gt;IsPrime&lt;/span&gt;()&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   36&lt;/span&gt;             &lt;span style="color: rgb(244, 122, 0);"&gt;select&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;n&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   37&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   38&lt;/span&gt;         &lt;span style="color: rgb(253, 223, 57);"&gt;result&lt;/span&gt; = &lt;span style="color: rgb(253, 223, 57);"&gt;primeNumbers&lt;/span&gt;.&lt;span style="color: rgb(253, 223, 57);"&gt;ToArray&lt;/span&gt;();&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   39&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   40&lt;/span&gt;     }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   41&lt;/span&gt;     &lt;span style="color: rgb(244, 122, 0);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;result&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   42&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   43&lt;/span&gt; &lt;/pre&gt;
&lt;/div&gt;
The @IsPrime@ method is the trick.
&lt;div style="border: 1px solid rgb(255, 255, 0); padding: 0.5em; background: black none repeat scroll 0% 50%; font-family: Consolas,'Courier New'; font-size: 10pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 1em; width: 600px;"&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   48&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   49&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IntExtensions&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   50&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   51&lt;/span&gt;     &lt;span style="color: rgb(244, 122, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;bool&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;IsPrime&lt;/span&gt;(&lt;span style="color: rgb(244, 122, 0);"&gt;this&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;p&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   52&lt;/span&gt;     {&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   53&lt;/span&gt;         &lt;span style="color: rgb(244, 122, 0);"&gt;bool&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;result&lt;/span&gt; = &lt;span style="color: rgb(244, 122, 0);"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   54&lt;/span&gt;         &lt;span style="color: rgb(244, 122, 0);"&gt;if&lt;/span&gt; (&lt;span style="color: rgb(253, 223, 57);"&gt;p&lt;/span&gt; &amp;gt; &lt;span style="color: yellow;"&gt;1&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   55&lt;/span&gt;         {   &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   56&lt;/span&gt;             &lt;span style="color: rgb(43, 145, 175);"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt;&amp;gt; &lt;span style="color: rgb(253, 223, 57);"&gt;testNumbers&lt;/span&gt; =&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   57&lt;/span&gt;                 &lt;span style="color: rgb(244, 122, 0);"&gt;from&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;n&lt;/span&gt; &lt;span style="color: rgb(244, 122, 0);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Enumerable&lt;/span&gt;.&lt;span style="color: rgb(253, 223, 57);"&gt;Range&lt;/span&gt;(&lt;span style="color: yellow;"&gt;2&lt;/span&gt;, (&lt;span style="color: rgb(244, 122, 0);"&gt;int&lt;/span&gt;)&lt;span style="color: rgb(43, 145, 175);"&gt;Math&lt;/span&gt;.&lt;span style="color: rgb(253, 223, 57);"&gt;Sqrt&lt;/span&gt;(&lt;span style="color: rgb(253, 223, 57);"&gt;p&lt;/span&gt;))&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   58&lt;/span&gt;                 &lt;span style="color: rgb(244, 122, 0);"&gt;where&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   59&lt;/span&gt;                     &lt;span style="color: rgb(253, 223, 57);"&gt;p&lt;/span&gt; != &lt;span style="color: rgb(253, 223, 57);"&gt;n&lt;/span&gt; &amp;amp;&amp;amp; &lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   60&lt;/span&gt;                     &lt;span style="color: rgb(253, 223, 57);"&gt;p&lt;/span&gt; % &lt;span style="color: rgb(253, 223, 57);"&gt;n&lt;/span&gt;&lt;span&gt; == &lt;/span&gt;&lt;span style="color: yellow;"&gt;0&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   61&lt;/span&gt;                 &lt;span style="color: rgb(244, 122, 0);"&gt;select&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;n&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   62&lt;/span&gt;             &lt;span style="color: rgb(253, 223, 57);"&gt;result&lt;/span&gt; = &lt;span style="color: rgb(253, 223, 57);"&gt;testNumbers&lt;/span&gt;.&lt;span style="color: rgb(253, 223, 57);"&gt;Count&lt;/span&gt;() == &lt;span style="color: yellow;"&gt;0&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   63&lt;/span&gt;         }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   64&lt;/span&gt;         &lt;span style="color: rgb(244, 122, 0);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(253, 223, 57);"&gt;result&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   65&lt;/span&gt;     }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   66&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;   67&lt;/span&gt; &lt;/pre&gt;
&lt;/div&gt;
This algorithm might look a little nicer (from a LINQ point of view), but it's tragically slow. Essentially, the code performs some heavy looping for each number in the range being tested. I could probably juice up the prime test a little bit by digging into some of the more advanced algorithms, but for now it was a fun exercise.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.jeffkwak.com/blog/postAttachments/SieveOfEratosthenes.zip"&gt;Download the Source&lt;/a&gt;&lt;img src="http://jeffkwak.com/blog/aggbug/26.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/DropInTheBucket/~4/e4xOz7EAIYU" height="1" width="1"/&gt;</description>
            <dc:creator>Jeff Kwak</dc:creator>
            <guid isPermaLink="false">http://jeffkwak.com/blog/archive/2008/03/27/refactoring-the-sieve-of-eratosthenes.aspx</guid>
            <pubDate>Thu, 27 Mar 2008 04:19:19 GMT</pubDate>
            <comments>http://jeffkwak.com/blog/archive/2008/03/27/refactoring-the-sieve-of-eratosthenes.aspx#feedback</comments>
            <wfw:commentRss>http://jeffkwak.com/blog/comments/commentRss/26.aspx</wfw:commentRss>
            <trackback:ping>http://jeffkwak.com/blog/services/trackbacks/26.aspx</trackback:ping>
        <feedburner:origLink>http://jeffkwak.com/blog/archive/2008/03/27/refactoring-the-sieve-of-eratosthenes.aspx</feedburner:origLink></item>
    </channel>
</rss>
