title: C# - Building an Array from Text File
body: <p>I am attempting to build an array of batting averages from a .txt file, but most of the resources I am finding online to assist in how to work this out either work with text in the following format:</p>
  
  <p>1 2 3 4 5</p>
  
  <p>2 3 4 5 6</p>
  
  <p>etc.</p>
  
  <p>... or in the following format:</p>
  
  <p>1, 2</p>
  
  <p>3, 4</p>
  
  <p>etc.</p>
  
  <p>Unfortunately, my text file is in the following format, and changing the format is not an option. Each odd <em>line</em> number denotes a player, with the following even <em>line</em> number being their average at bat in that instance (just information for context):</p>
  
  <p>1</p>
  
  <p>2</p>
  
  <p>3</p>
  
  <p>4</p>
  
  <p>Using this file, I want to assign the odd numbers to the index of the array, and then populate the even numbers as values, calculating them as I go. I believe that I can parse out how to accomplish the calculations, I just cannot ascertain how to grab the data nor associate the odd numbers with array indexes.</p>
  
  <p>Code as follows. File is to be specified by user:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.IO;
  
  static string FileName()
      {
          string doc = Console.ReadLine();
          return doc;
      }
  
  static void Main(string[] args)
      {
  
          try
          {
  
              Console.Write("Where is the data file for batting averages located? ");
              string doc = FileName();
              StreamReader reader = new StreamReader(doc);
              string avg = reader.ReadToEnd();
              reader.Close();
  
          }
          catch (System.IO.FileNotFoundException) 
          {
              Console.WriteLine("The file can not be found.");
          }
          catch (System.FormatException)
          {
              Console.WriteLine("Invalid file.");
          }
          catch (System.ArgumentException)
          {
              Console.WriteLine("Enter a valid file name.");
          }
          catch (System.Exception exc)
          {
              Console.WriteLine(exc.Message);
          }
      }
  </code></pre>
  
  <p>Any assistance would be welcome. Please keep in mind I am a student and still learning the earliest parts of C#, so any truly advanced techniques are probably going to be lost on me.</p>