Find two numbers in an array whose sum =X

Solution : Here is the idea is to start from the first element of the array and keep a Hashtable to store the potential pairs. We will check  if sum – (a[i])  already exists in the Hashtable . If yes, we have a pair (a[i], value from Hashtable ) as the pair with the sum. If no, we store a[i] in the Hashtable .

Here is a little dry run of array a= {1,2,3,4,5,6,7,8} and sum = 6.

  1. 6 – 1 = 5  — found in Hashtable H ? No – store it in H.  H will contain (1)
  2. 6 –2 = 4 – found in Hashtable H ? No – store it in H.  H will contain (1, 2)
  3. 6 –3 = 4 – found in Hashtable H ? No – store it in H.  H will contain (1, 2, 3)
  4. 6 –4 = 2 – found in Hashtable H ? Yes – now we have a pair (a[i] , found in H) – (4,2)
  5. 6 –5 = 1 – found in Hashtable H ? Yes – now we have a pair (a[i] , found in H) – (5,1)
public static void TargetSum(int[] array, int target)
    {

      Dictionary<int, int> hashMap = new Dictionary<int, int>();

      int lookup = 0;

      for (int i = 0; i < array.Length; i++)
      {
        lookup = target - array[i];

        if (hashMap.ContainsKey(lookup) == true)
        {
          Console.WriteLine("Pair {0},{1}", lookup, array[i]);

        }
        else
        {
          hashMap.Add(array[i], array[i]);
        }
      }



    }

Visual Studio LightSwitch: An Integrated Development Environment for Managers

Microsoft is working on product called LightSwitch and release a beta version of Visual Studio LightSwitch on August 23, 2010. Visual Studio LightSwitch will come with pre-configured templates, pre-written code and other reusable components. Visual Studio LightSwitch also allows users to write custom code in Visual Basic .NET or C#. Applications developed using LightSwitch can be deployed on desktop, browser or on cloud.

Applications created with LightSwitch support exporting data to Microsoft Office Excel for fast and easy sharing and reporting. You can also attach your application to existing data sources, which makes it easy to collect, analyze, and reuse information from a variety of data sources including Microsoft SQL Server, Microsoft SQL Azure, SharePoint, Microsoft Office Access (post-Beta), and other third-party data sources.

With LightSwitch you can create custom applications for the way you do business. Keep your technology and business options open, while building a practical yet scalable application that matches your current needs now and in the future. The pre-built templates and components in LightSwitch are fully extensible, so you can get the specific functionality your application demands. In addition, your application can grow to meet the increasing demands of popular applications using the Microsoft Windows Azure Cloud Hosting option.