Example #1
0
    public void TerminateEmployee(int index)
    {
      // Clone sensitive objects.
      var tempActiveEmployees = (ArrayList)_activeEmployees.Clone();
      var tempTerminatedEmployees = (ArrayList)_terminatedEmployees.Clone();

      // Perform actions on temp objects.
      object employee = tempActiveEmployees[index];
      tempActiveEmployees.RemoveAt(index);
      tempTerminatedEmployees.Add(employee);

      //  RuntimeHelpers.PrepareConstrainedRegions();
      try
      {
        Console.WriteLine("In try");
      }
      finally
      {
        Swapper.ListSwap(ref _activeEmployees, ref tempActiveEmployees);
        Swapper.ListSwap(ref _terminatedEmployees, ref tempTerminatedEmployees);
      }

      // Keep the console window open in debug mode.
      Console.WriteLine("Press any key to exit.");
      Console.ReadKey();
    }