Şu anda bu, yalnızca 0'ları gösteren ve Console.Write (string.Format ("{0,6} |", arr [j, için bir IndexOutOfRangeException atar bir satır içeren bir tablo görüntüler. ben])); Her metin dosyasındaki bilgileri tablo formatında yazdırmak istiyorum. Sorunun nerede olduğunu1D dizisini bir 2D dizinin sütununda nasıl depolarım? Bu, şu ana kadar benim kodum:
// 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();
}
, çiftlerde senin dizinin beyanı (? 'Arr') kimliği eksik gibi görünüyor. –
Teşekkürler, orijinal kodumda var ... Sadece doğru şekilde kopyalamamıştım. – MrLogic
Olası kopyası: http://stackoverflow.com/questions/20940979/what-is-indexoutofrangeexception-and-how-do-i-fix-it – Mikanikal