Currently this displays a table with one row that just shows 0's and throws an IndexOutOfRangeException for the Console.Write(string.Format("{0,6} |", arr[j, i])); I want to print the information in each text file in a table format.
// StringToDouble is a method that converts the contents of the text file to double
public static double[] Year = StringToDouble("Year.txt");
public static double[] TMax = StringToDouble("WS1_TMax.txt");
public static double[] TMin = StringToDouble("WS1_TMin.txt");
public static double[] AF = StringToDouble("WS1_AF.txt");
public static double[] Rain = StringToDouble("WS1_Rain.txt");
public static double[] Sun = StringToDouble("WS1_Sun.txt");
static void Main(string[] args)
{
double[,] arr = new double[6, 1021]; // 1021 is the upper bound of my array
int rowLength = arr.GetLength(0);
int colLength = arr.GetLength(1);
for (int i = 0; i < rowLength; i++)
{
for (int j = 0; j < colLength; j++)
{
// The arrays Year[], TMax[], etc... are declared outside the Main
arr[i, 1] = Year[j];
arr[i, 2] = TMax[j];
arr[i, 3] = TMin[j];
arr[i, 4] = AF[j];
arr[i, 5] = Rain[j];
arr[i, 6] = Sun[j];
}
}
Console.WriteLine(" Years| TMax | TMin | AF | Rain | Sun |");
for (int i = 0; i < rowLength; i++)
{
for (int j = 0; j < colLength; j++)
{
Console.Write(string.Format("{0,6} |", arr[j, i]));
}
Console.Write(Environment.NewLine);
}
Console.ReadKey();
}