C# getting a jagged array from a method call -
i have jagged array , works fine in main
if try put in method i'm unsure call. i've tried load(data)
, return statements haven't had luck.
public static void load() { try { string[][] data = new[] { file.readalllines(@"data\month.txt"), file.readalllines(@"data\year.txt"), file.readalllines(@"data\ws1_af.txt"), file.readalllines(@"data\ws1_rain.txt"), file.readalllines(@"data\ws1_sun.txt"), file.readalllines(@"data\ws1_tmin.txt"), file.readalllines(@"data\ws1_tmax.txt"), }; console.writeline("files have been found, press key continue"); console.readkey(); } catch (exception) { console.writeline("unable find files... exiting"); exit(); } }
simply return array method , change return type of load
method same type array you're returning has (void
means you're returning nothing). also, it's better idea handle exceptions on higher level:
public static string[][] load() { string[][] data = new[] { file.readalllines(@"data\month.txt"), file.readalllines(@"data\year.txt"), file.readalllines(@"data\ws1_af.txt"), file.readalllines(@"data\ws1_rain.txt"), file.readalllines(@"data\ws1_sun.txt"), file.readalllines(@"data\ws1_tmin.txt"), file.readalllines(@"data\ws1_tmax.txt"), }; return data; } public static void test() { try { var data = load(); console.writeline("files have been found, press key continue"); console.readkey(); } catch (exception) { console.writeline("unable find files... exiting"); exit(); } }
Comments
Post a Comment