title: ArrayList conversion using Linq
body: <p>***I sincerely apologise as I should have posted the complete code.</p>
  
  <p>I have an application where I have an IUIAutomationElementArray and I have cached data regarding bounding rectangles of each IUIAutomationElement from the array. I am then converting these to WPF borders</p>
  
  <pre><code>public class NumberRectangle : Border, IComparable
  {
  </code></pre>
  
  <p>currently I am using iteration to convert the IUIAutomationElementArray to an array list of rectangles seen in the method declaration below.</p>
  
  <pre><code> public ArrayList createRectangles(IUIAutomationElementArray elements)           
      {
          // create an array list to hold the rectangles
          rectArray = new ArrayList();                                                            
          for (int i = 0; i &lt; elements.Length; i++)
          {
              IUIAutomationElement currentElement = elements.GetElement(i);
              //create DragonNumberRectangle to represent automation element
              NumberRectangle currentRectangle = new NumberRectangle(currentElement);
              //set horizontal and vertical alignment in order to align rectangles properly on window
              currentRectangle.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;             
              currentRectangle.VerticalAlignment = System.Windows.VerticalAlignment.Top;
              currentRectangle.Height = (currentElement.CachedBoundingRectangle.bottom - currentElement.CachedBoundingRectangle.top);
              currentRectangle.Width = (currentElement.CachedBoundingRectangle.right - currentElement.CachedBoundingRectangle.left);
              // Thickness object represents Margin property of NumberRectangle (which is basically a Border)        
              Thickness rectThickness = new Thickness();
              //set Left and Top for position of rectangle
              rectThickness.Left = (currentElement.CachedBoundingRectangle.left);             
              rectThickness.Top = (currentElement.CachedBoundingRectangle.top);
  
              currentRectangle.Margin = rectThickness;
              // add colour rectangle to the list of rectangles
              rectArray.Add(currentRectangle);                                                                                                                                                            
          }
          //sort the rectangles to number from left to right/top to bottom
          rectArray.Sort();                                                                                     
          return rectArray;
      }    
  </code></pre>
  
  <p>I then draw the borders on a WPF window. The issue is that the createRectangles metho takes one second of processing time where the conversion of the element  array to rectangles is the predominant time waster.</p>
  
  <p>So the question is can I do this with Linq and how would I do this with Linq, an example would be great as I am not familiar with Linq currently. Perhaps the real question is how do I speed this up?</p>