title: Retrieving objects from ArrayList - cast to type?
body: <p>I'm taking a basic course in C# programming, and this is a part of our assignment.
  Very new to programming so I feel more than a bit lost with this.</p>
  
  <p>The assignment is to add an <code>ArrayList</code> and insert strings from a file to this, which I hopefully have done with the code below:  </p>
  
  <ul>
  <li><p><code>Read ()</code> is a method in another class (<code>FileReader</code>) that reads the files from <code>"info.txt"</code> and returns an <code>ArrayList</code>.</p></li>
  <li><p>The <code>ArrayList</code> items are supposed to store the object items, although I'm not quite sure why I need two arrays?</p></li>
  </ul>
  
  <p>The problem I have is: when you retrieve the "items" from the array, they have to be cast to a type, <code>string</code>, (if I understand it correctly, otherwise they are returned as <code>objects</code>?). How do I do that?</p>
  
  <p>Can you cast the entire <code>ArrayList</code>?</p>
  
  <pre><code>public PriceFlux ()  //Constructor
  {
      ArrayList items;          
      items = new ArrayList();
      FileReader infoFile = new FileReader("info.txt"); 
      items = infoFile.Read();   
  }
  </code></pre>
  
  <p>The files from the <code>info.txt</code> looks approximately like this:</p>
  
  <blockquote>
    <p>G&amp;34&amp;Kellogs K frukostflingor&amp;Sverige&amp;29.50&amp;5/11/2005&amp;29/10/2005&amp;29/10/2006</p>
  </blockquote>
  
  <p>Here is the <code>FileReader Read()</code> method:</p>
  
  <pre><code>public ArrayList Read ()
  {
      ArrayList fileContent = new ArrayList ();
      try
      {                               
          while (line != null)
          {   
              fileContent.Add (line);
              line = reader.ReadLine ();
          }
          reader.Close ();
      } 
      catch
      {
          Console.WriteLine ("Couldn´t read from file.");
      }
      return fileContent;
  }
  </code></pre>
  
  <p>Very grateful for suggestions on how to solve this.</p>