Monday, 27 May 2013

Sequence that events are raised for Pages, UserControls, MasterPages and HttpModules

Understanding the Page Life Cycle can be very important as you begin to build Pages with MasterPages and UserControls.
Does the Init event fire first for the Page, the MasterPage or the UserControl? 
What about the Load event?

If you make an incorrect assumption about the sequence that these events fire, then you may end up with a page that simply doesn't behave the way you had anticipated.
By running a simple test, we can see exactly when each event fires.  Our test setup is composed of a Page, MasterPage, UserControl, Nested UserControl and Button control as follows:
  • The Page is tied to the MasterPage
  • The UserControl is on the Page
  • The Nested UserControl is on the UserControl
  • The Button is on the Nested UserControl.
  • Clicking the Button calls the Page.DataBind method
Each event on these controls has been set to call Debug.WriteLine as each event is raised.  In addition to the events that get raised for regular pages, I've also set up an HttpModule and wired up all of those events as well. The results in the Debug output window of running this page and Clicking the Button are as follows:

BeginRequest - HttpModule
AuthenticateRequest - HttpModule
PostAuthenticateRequest - HttpModule
PostAuthorizeRequest - HttpModule
ResolveRequestCache - HttpModule
PostResolveRequestCache - HttpModule
PostMapRequestHandler - HttpModule
AcquireRequestState - HttpModule
PostAcquireRequestState - HttpModule
PreRequestHandlerExecute - HttpModule


PreInit - Page

Init - ChildUserControl
Init - UserControl
Init - MasterPage
Init - Page


InitComplete - Page

LoadPageStateFromPersistenceMedium - Page 

ProcessPostData (first try) - Page
PreLoad - Page

Load - Page
Load - MasterPage
Load - UserControl
Load - ChildUserControl

ProcessPostData (second try) - Page
RaiseChangedEvents - Page
RaisePostBackEvent - Page

Click - Button - ChildUserControl
    DataBinding - Page
    DataBinding - MasterPage
    DataBinding - UserControl
    DataBinding - ChildUserControl

LoadComplete - Page

PreRender - Page
PreRender - MasterPage
PreRender - UserControl
PreRender - ChildUserControl

PreRenderComplete - Page

SaveViewState - Page
SavePageStateToPersistenceMedium - Page
SaveStateComplete - Page


Unload - ChildUserControl
Unload - UserControl
Unload - MasterPage
Unload - Page


PostRequestHandlerExecute - HttpModule
ReleaseRequestState - HttpModule
PostReleaseRequestState - HttpModule
UpdateRequestCache - HttpModule
PostUpdateRequestCache - HttpModule
EndRequest - HttpModule
PreSendRequestHeaders - HttpModule
PreSendRequestContent - HttpModule 

Wednesday, 27 February 2013

Parallel Programming in .Net

Introduction to TPL(Task Parallel Library)

I have to admit that I’m not an expert in multithreading or parallel computing. However, people often ask me about easy introductions and beginner’s samples for new features. And I have an enormous advantage over most newbies in this area – I can ask people who developed this library about what I’m doing wrong and what to do next. By the way, if you want to ask someone about what to do next with your parallel program, I'd recommend you to go to this forum  Parallel Extensions to the .NET Framework Forum.

I have a simple goal this time. I want to parallelize a long-running console application and add a responsive WPF UI. By the way, I’m not going to concentrate too much on measuring performance. I’ll try to show the most common caveats, but in most cases just seeing that the application runs faster is good enough for me.
Now, let the journey begin. Here’s my small program that I want to parallelize. The SumRootN method returns the sum of the nth root of all integers from one to 10 million, where n is a parameter. In the Main method, I call this method for roots from 2 through 19. I’m using the Stopwatch class to check how many milliseconds the program takes to run

using System.Threading.Tasks;
using System.Threading;
using System.Diagnostics;
using System;

class Program
{

    static void Main(string[] args)
    {
        var watch = Stopwatch.StartNew();
        for (int i = 2; i < 20; i++)
        {
            var result = SumRootN(i);
            Console.WriteLine("root {0} : {1} ", i, result);
        }
        Console.WriteLine(watch.ElapsedMilliseconds);
        Console.ReadLine();
    }

    public static double SumRootN(int root)
    {
        double result = 0;
        for (int i = 1; i < 10000000; i++)
        {
            result += Math.Exp(Math.Log(i) / root);
        }
        return result;
    }
}
On my 3-GHz dual-core 64-bit computer with 4 GB of RAM the program takes about 18 seconds to run.
Since I’m using a for loop, the Parallel.For method is the easiest way to add parallelism. All I need to do is replace

for (int i = 2; i < 20; i++)
{
    var result = SumRootN(i);
    Console.WriteLine("root {0} : {1} ", i, result);
}

Parallel.For(2, 20, (i) =>
{
    var result = SumRootN(i);
    Console.WriteLine("root {0} : {1} ", i, result);
});
Notice how little the code changed. I supplied start and end indices (same as I did in the simple loop) and a delegate in the form of a lambda expression. I didn’t have to change anything else, and now my little program takes about 9 seconds.
When you use the Parallel.For method, the .NET Framework automatically manages the threads that service the loop, so you don’t need to do this yourself. But remember that running code in parallel on two processors does not guarantee that the code will run exactly twice as fast. Nothing comes for free; although you don’t need to manage threads yourself, the .NET Framework still uses them behind the scenes. And of course this leads to some overhead. In fact, if your operation is simple and fast and you run a lot of short parallel cycles, you may get much less benefit from parallelization than you might expect.
Another thing you probably noticed when you run the code is that now you don’t see the results in the proper order: Instead of seeing increasing roots, you see quite a different picture. But let’s pretend that we just need results, without any specific order. In this blog post, I’m going to leave this problem unresolved.
Now it’s time to take things one step further. I don’t want to write a console application; I want some UI. So I’m switching to Windows Presentation Foundation (WPF). I have created a small window that has only one Start button, one text block to display results, and one label to show elapsed time.
The event handler for the sequential execution looks pretty simple:

private void start_Click(object sender, RoutedEventArgs e)
{
    textBlock1.Text = "";
    label1.Content = "Milliseconds: ";

    var watch = Stopwatch.StartNew();
    for (int i = 2; i < 20; i++)
    {
        var result = SumRootN(i);
        textBlock1.Text += "root " + i.ToString() + " " +
                           result.ToString() + Environment.NewLine;

    }
    var time = watch.ElapsedMilliseconds;
    label1.Content += time.ToString();
}

Compile and run the application to make sure that everything works fine. As you might notice, UI is frozen and the text block does not update until all of the computations are done. This is a good demonstration of why WPF recommends never executing long-running operations in the UI thread.
Let’s change the for loop to the parallel one:

Parallel.For(2, 20, (i) =>
{
    var result = SumRootN(i);
    textBlock1.Text += "root " + i.ToString() + " " +
                        result.ToString() + Environment.NewLine;

});

Click the button…and…get an InvalidOperationException that says “The calling thread cannot access this object because a different thread owns it.”
What happened? Well, as I mentioned earlier, the Task Parallel Library still uses threads. When you call the Parallel.For method, the .NET Framework starts new threads automatically. I didn’t have problems with the console application because the Console class is thread safe. But in WPF, UI components can be safely accessed only by a dedicated UI thread. Since Parallel.For uses worker threads besides the UI thread, it’s unsafe to manipulate the text block directly in the parallel loop body. If you use, let’s say, Windows Forms, you might have different problems, but problems nonetheless (another exception or even an application crash).
Luckily, WPF provides an API that solves this problem. Most controls have a special Dispatcher object that enables other threads to interact with the UI thread by sending asynchronous messages to it. So our parallel loop should actually look like this:

Parallel.For(2, 20, (i) =>
{
    var result = SumRootN(i);
    this.Dispatcher.BeginInvoke(new Action(() =>
        textBlock1.Text += "root " + i.ToString() + " " +
                           result.ToString() + Environment.NewLine)
         , null);
});

In the above code, I’m using the Dispatcher to send a delegate to the UI thread. The delegate will be executed when the UI thread is idle. If UI is busy doing something else, the delegate will be put into a queue. But remember that this type of interaction with the UI thread may slow down your application.
Now I have our parallel WPF application running on my computer almost twice fast. But what about this freezing UI? Don’t all modern applications have responsive UI? And if Parallel.For starts new threads, why is the UI thread still blocked?
The reason is that Parallel.For tries to exactly imitate the behavior of the normal for loop, so it blocks the further code execution until it finishes all its work.
Let’s take a short pause here. If you already have an application that works and satisfies all your requirements, and you want to simply speed it up by using parallel processing, it might be enough just to replace some of the loops with Parallel.For or Parallel.ForEach. But in many cases you need more advanced tools.
To make the UI responsive, I am going to use tasks, which is a new concept introduced by the Task Parallel Library. A task represents an asynchronous operation that is often run on a separate thread. The .NET Framework optimizes load balancing and also provides a nice API for managing tasks and making asynchronous calls between them. To start an asynchronous operation, I’ll use the Task.Factory.StartNew method.
So I’ll delete the Parallel.For and replace it with the following code, once again trying to change as little as possible.
for (int i = 2; i < 20; i++)
{
    var t = Task.Factory.StartNew(() =>
    {
        var result = SumRootN(i);
        this.Dispatcher.BeginInvoke(new Action(() =>
            textBlock1.Text += "root " + i.ToString() + " " +
               result.ToString() + Environment.NewLine)
            ,null);

    });
}
Compile, run… Well, UI is responsive. I can move and resize the window while the program calculates the results. But I have two problems now:
1. My program tells me that it took 0 milliseconds to execute.
2. The program calculates the method only for root 20 and shows me a list of identical results.
Let’s start with the last one. C# experts can shout it out: closure! Yes, i is used in a loop, so when a thread starts working, i’s value has already changed. Since i is equal to 20 when the loop is exited, this is the value that is always passed to newly created tasks.
Problems with closure like this one are common when you deal with lots of delegates in the form of lambda expressions (which is almost inevitable with asynchronous programming), so watch out for it. The solution is really easy. Just copy the value of the loop variable into a variable declared within the loop. Then use this local variable instead of the loop variable

for (int i = 2; i < 20; i++)
{
    int j = i;
    var t = Task.Factory.StartNew(() =>
    {
        var result = SumRootN(j);
        this.Dispatcher.BeginInvoke(new Action(() =>
             textBlock1.Text += "root " + j.ToString() + " " +
                                 result.ToString() + Environment.NewLine)
             , null);
    });
}
Now let’s move to the second problem: The execution time isn’t measured. I perform the tasks asynchronously, so nothing blocks the code execution. The program starts the tasks and goes to the next line, which is reading time and displaying it. And it doesn’t take that long, so I get 0 on my timer.
Sometimes it’s OK to move on without waiting for the threads to finish their jobs. But sometimes you need to get a signal that the work is done, because it affects your workflow. A timer is a good example of the second scenario.
To get my time measurement, I have to wrap code that reads the timer value into yet another method from the Task Parallel Library: TaskFactory.ContinueWhenAll. It does exactly what I need: It waits for all the threads in an array to finish and then executes the delegate. This method works on arrays only, so I need to store all the tasks somewhere to be able to wait for them all to finish.
Here’s what my final code looks like:
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }
    public static double SumRootN(int root)
    {
        double result = 0;
        for (int i = 1; i < 10000000; i++)
        {
            result += Math.Exp(Math.Log(i) / root);
        }
        return result;
    }

    private void start_Click(object sender, RoutedEventArgs e)
    {
        textBlock1.Text = "";
        label1.Content = "Milliseconds: ";

        var watch = Stopwatch.StartNew();
        List<Task> tasks = new List<Task>();
        for (int i = 2; i < 20; i++)
        {
            int j = i;
            var t = Task.Factory.StartNew(() =>
            {
                var result = SumRootN(j);
                this.Dispatcher.BeginInvoke(new Action(() =>
                     textBlock1.Text += "root " + j.ToString() + " " +
                                         result.ToString() +
                                         Environment.NewLine)
                , null);
            });
            tasks.Add(t);
        }

        Task.Factory.ContinueWhenAll(tasks.ToArray(),
              result =>
              {
                  var time = watch.ElapsedMilliseconds;
                  this.Dispatcher.BeginInvoke(new Action(() =>
                      label1.Content += time.ToString()));
              });

    }
}
Finally, everything works as expected: I have a list of results, the UI does not freeze, and the elapsed time displays correctly. The code definitely looks quite different from what I started with, but surprisingly it’s not that long, and I was able to reuse most of it (thanks to lambda expression syntax).
Again, I tried to cover common problems that most beginners in parallel programming and multithreading are likely to encounter, without getting too deep into details

Sunday, 13 January 2013

Interview Questions on oops

1. How to prevent a class from being inherited?

In order to prevent a class in C# from being inherited, the keyword sealed is used. Thus a sealed class may not serve as a base class of any other class. It is also obvious that a sealed class cannot be an abstract class. Code below...

//C# Examplesealed class ClassA{    public int x;    public int y;}


No class can inherit from ClassA defined above. Instances of ClassA may be created and its members may then be accessed, but nothing like the code below is possible...

class DerivedClass : ClassA { } // Error

2. Implementation inheritance and interface inheritance?

  • When a class is derived from another class in such a way that it will inherit all its members to its corresponding derived class, then it is implementation inheritance. 
  • When a class inherits only the signatures of the functions from its corresponding base class, then it is interface inheritance.

  • 3. How to: Explicitly Implement Interface Members with Inheritance
      Explicit interface implementation also allows the programmer to implement two interfaces that have the same member names and give each interface member a separate implementation. This example displays the dimensions of a box in both metric and English units. The Box class implements two interfaces IEnglishDimensions and IMetricDimensions, which represent the different measurement systems. Both interfaces have identical member names, Length and Width

    // Declare the English units interface:
    interface IEnglishDimensions
    {
        float Length();
        float Width();
    }

    // Declare the metric units interface:
    interface IMetricDimensions
    {
        float Length();
        float Width();
    }

    // Declare the Box class that implements the two interfaces:
    // IEnglishDimensions and IMetricDimensions:
    class Box : IEnglishDimensions, IMetricDimensions
    {
        float lengthInches;
        float widthInches;

        public Box(float length, float width)
        {
            lengthInches = length;
            widthInches = width;
        }

        // Explicitly implement the members of IEnglishDimensions:
        float IEnglishDimensions.Length()
        {
            return lengthInches;
        }

        float IEnglishDimensions.Width()
        {
            return widthInches;
        }

        // Explicitly implement the members of IMetricDimensions:
        float IMetricDimensions.Length()
        {
            return lengthInches * 2.54f;
        }

        float IMetricDimensions.Width()
        {
            return widthInches * 2.54f;
        }

        static void Main()
        {
            // Declare a class instance box1:
            Box box1 = new Box(30.0f, 20.0f);

            // Declare an instance of the English units interface:
            IEnglishDimensions eDimensions = (IEnglishDimensions)box1;

            // Declare an instance of the metric units interface:
            IMetricDimensions mDimensions = (IMetricDimensions)box1;

            // Print dimensions in English units:
            System.Console.WriteLine("Length(in): {0}", eDimensions.Length());
            System.Console.WriteLine("Width (in): {0}", eDimensions.Width());

            // Print dimensions in metric units:
            System.Console.WriteLine("Length(cm): {0}", mDimensions.Length());
            System.Console.WriteLine("Width (cm): {0}", mDimensions.Width());
        }
    }



    4. Access the base class method with derived class objects

    First cast the derived class object to base class type and if you call method it invokes base class method. Keep in mind it works only when derived class method is shadowed


    public class BaseClass{    public void Method1()    {        string a = "Base method";    }}
    public class DerivedClass : BaseClass{    public new void Method1()    {        string a = "Derived Method";    }}
    public class TestApp{    public static void main()    {        DerivedClass derivedObj = new DerivedClass();        BaseClass obj2 = (BaseClass)derivedObj;        obj2.Method1();  // invokes Baseclass method
        }}


    5.Difference between ‘Shadowing’ and ‘Overriding’ (Shadowing vs Overriding) – C#


    Shadowing : Creating an entirely new method with the same signature as one in a base class.
    Overriding: Redefining an existing method on a base class.
    • Both are used when a derived class inherits from a base class
    Both redefine one or more of the base class elements in the derived class

    class A
     {
     public int M1()
     {
     return 1;
     }
     public virtual int M2()
     {
     return 1;
     }
     }
    class B : A
     {
     public new int M1()
     {
     return 2;
     }
     public override int M2()
     {
     return 2;
     }
     }
    class Program
     {
     static void Main(string[] args)
     {
     B b = new B();
     A a = (A)b;
     Console.WriteLine(a.M1()); //Base Method
     Console.WriteLine(a.M2());&nbsp;//Override Method
     Console.WriteLine(b.M1());
     Console.WriteLine(b.M2());
     Console.Read();
     }
     }
    6. Shadowing vs Overriding

    It is easy to confuse shadowing with overriding. Both are used when a derived class inherits from a base class, and both redefine one declared element with another. But there are significant differences between the two.

    You normally use overriding in the following cases:
    • You are defining polymorphic derived classes.
    • You want the safety of having the compiler enforce the identical element type and calling sequence.
    You normally use shadowing in the following cases:
    • You anticipate that your base class might be modified and define an element using the same name as yours.
    • You want the freedom of changing the element type or calling sequence.


    suppose you have this classes:

    class A {
       public int Foo(){ return 5;}
       public virtual int Bar(){return 5;}
    }
    class B : A{
       public new int Foo() { return 1;}
       public override int Bar() {return 1;}
    }

    then when you call this:

    A clA = new A();
    B clB = new B();

    Console.WriteLine(clA.Foo()); // output 5
    Console.WriteLine(clA.Bar()); // output 5
    Console.WriteLine(clB.Foo()); // output 1
    Console.WriteLine(clB.Bar()); // output 1

    //now let's cast B to an A class
    Console.WriteLine(((A)clB).Foo()); // output 5 <<<--
    Console.WriteLine(((A)clB).Bar()); // output 1

    Suppose you have a base class and you use the base class in all your code instead of the inherited classes, and you use shadow, it will return the values the base class returns instead of following the ineritance tree of the real type of the object.
    7. Common c# Interfaces
    System.Configuration.IApplicationSettingsProvider System.Linq.IQueryable
    System.Configuration.IConfigurationSectionHandler System.Net.ICredentials
    System.Data.IDataAdapter System.Web.IHttpHandler
    System.Data.IDataParameter System.Web.IHttpModule
    System.Data.IDataReader System.Web.SessionState.IHttpSessionState
    System.Data.IDbCommand System.Web.SessionState.IReadOnlySessionState
    System.Data.IDbConnection System.Web.SessionState.IRequiresSessionState
    System.Data.IDbDataAdapter System.Xml.Serialization.IXmlSerializable
    System.Security.Principal.IPrincipal System.Security.Principal.IIdentity

    Wednesday, 12 December 2012

    Logging Event with C# and .Net Framework into Event Log

    We can use Event log to store any error that our application generates as a result of testing or daily usage by the users. It is very useful when we are trying to log error messages which are events as well. The primary advantage is that we can see very detailed report of errors that occurred. This is much better mechanism of capturing errors since users may not always describe to us what the nature of the error is that they are getting via the interface. However, there are couple very serous considerations we have to take into account. First, Event Log must be run under very strict security framework. Second, Event Log is process intensive operation. Finally, Event Log can throw exceptions if Event Log is filled. Event log should be avoided with partial trust assemblies.   In order to create Event Log and write to it we need to use EventLog class.

    public static void CreateEventLog()
    {
         
    EventLog DemoLog = new EventLog("Demo");
         DemoLog.Source = "Demo";
         //WriteEntry
         DemoLog.WriteEntry("CreateEventLog call", EventLogEntryType.Information);
    } This will crate an entry in our list of Event Logs.     If we want to remove Event Log that we just created we’ll do it the following waypublic static void DeleteEvantLog()
    {
       EventLog.Delete("Demo");
    }
      EventLog is also useful to work with Built-in Event Logs such as Application Log, Security Log and System Log. Example of writing to Event Logpublic static void WriteToApplicationEventLog()
    {
                EventLog DemoLog = new EventLog("Application");
                

    DemoLog.Source = "DemoApp";
                DemoLog.WriteEntry("Written to Application Log",  EventLogEntryType.Information);
    }     Reading from Event Log is very important if we try to display errors or failed attempt to run application to the web. We can do this using following code.public static void ReadEventLog()
    {
         EventLog MyDemoLog = new EventLog();
         MyDemoLog.Log = "Demo";
         foreach (EventLogEntry MyDemoEntry in MyDemoLog.Entries)
         {
          Console.WriteLine(MyDemoEntry.Source + ":" + MyDemoEntry.Message);
         }
    }
        Clearing Log is even simpler.public static void ClearEventLog()
       {
         EventLog MyLogDemo = new EventLog("Demo");
         MyLogDemo.Source = "DemoApp";
         MyLogDemo.Clear();
       }

    C# Stopwatch

    Stopwatch measures time elapsed. It is useful for micro-benchmarks in code optimization. It can perform routine and continuous performance monitoring. The Stopwatch type, found in System.Diagnostics, is useful in many contexts
    Example
    First, Stopwatch is a class in the .NET Framework that is ideal for timing any operation in your C# programs. You must create Stopwatch as an instance. This makes it useful in multithreaded applications or websites.
    Program that uses Stopwatch [C#]
    
    using System;
    using System.Diagnostics;
    using System.Threading;
    
    class Program
    {
        static void Main()
        {
     // Create new stopwatch
     Stopwatch stopwatch = new Stopwatch();
    
     // Begin timing
     stopwatch.Start();
    
     // Do something
     for (int i = 0; i < 1000; i++)
     {
         Thread.Sleep(1);
     }
    
     // Stop timing
     stopwatch.Stop();
    
     // Write result
     Console.WriteLine("Time elapsed: {0}",
         stopwatch.Elapsed);
        }
    }
    
    Output
    
    Time elapsed: 00:00:01.0001477

    The code includes the "using System.Diagnostics" namespace at the top. This is where the Stopwatch class is defined in the Framework. You can see the Stopwatch is created with the new operator in Main

    Thursday, 29 November 2012

    Global Exception Handling in different types of applications

    1. Asp.net

    System.Web.HttpApplication.Error event

    Usually setup in Global.asax

    MSDN: How to: Handle Application-Level errors.
    Also see:
    Complete example for Error Handlers

    2. WinForms:

    System.Windows.Forms.Application.ThreadException
    event
    MSDN: Application.ThreadException event
    Blog: Top-Level Exception Handling In Windows Forms Applications
    // Add the event handler for handling UI thread exceptions to the event.
    Application.ThreadException += new ThreadExceptionEventHandler(ErrorHandlerForm.Form1_UIThreadException);
    
    // Set the unhandled exception mode to force all Windows Forms errors to go through
    // our handler.
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
    
    // Add the event handler for handling non-UI thread exceptions to the event. 
    AppDomain.CurrentDomain.UnhandledException +=
            new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

    3. Console applications (also should work with Windows Services – havent checked this though):
    System.AppDomain.UnhandledException event
    MSDN: AppDomain.UnhandledException Event

    AppDomain currentDomain = AppDomain.CurrentDomain;
    currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
    4. WPF:

    System.Windows.Application.DispatcherUnhandledException

    MSDN: Application.DispatcherUnhandledException Event
    public App() :base() //App.xaml.cs
    {
            this.Dispatcher.UnhandledException += OnDispatcherUnhandledException;
    }

    Also see: WPF Global Exception Handler (StackOverflow)

    5. Silverlight:

    Application.UnhandledException Event

    MSDN: Application.UnhandledException Event
    Also see:
    Silverlight Error Handling
    public App()//App.xaml.cs
    {
            this.UnhandledException += this.Application_UnhandledException;
            InitializeComponent();
    }
    private void Application_UnhandledException(object sender,ApplicationUnhandledExceptionEventArgs e)
    {
            //handle exception here.
    }
    Also take a look at the EntLib Patterns and Practices pack for Silverlight (codeplex.com) {Logging Application Block}

    Monday, 19 November 2012

    LINQ : LINQPad

     LINQPad lets you interactively query databases in a modern query language: LINQ.  Kiss goodbye to SQL Management Studio
    LINQPad supports everything in C# 4.0/5.0 and Framework 4:
    And that's not all - there's also specific support for:
    And LINQPad is more than a LINQ tool: it's an ergonomic C#/VB/F# scratchpad that instantly executes any expression, statement block or program with rich output formatting – the ultimate in dynamic development. Put an end to those hundreds of Visual Studio Console projects cluttering your source folder

    LINQPad Screenshot

    Source : http://www.linqpad.net/