Lets say I have some known library to load data from an .xls file and returns a DataTable populated with data from the first sheet in any excel workbook. Also a Log function that prints out messages in the absence of a working debugger.
DataTable dtFoo = null;
DataTable dtBar = null;
DataTable dtChaz = null;
String[] files = new String[]{ "file1.xls", "file2.xls", "file2.xls" };
DataTable[] dts = new DataTable[] { dtFoo, dtBar, dtChaz };
for(int i = 0; i < 3; i++)
{
dts[i] = SomeLibrary.LoadFromFile(files[i]); //Returns a new DataTable
Log((dts[i] == null) + " " + dts[i].Rows.Count)
}
Log((dts[0] == null) + " " + (dtFoo == null));
Log((dts[1] == null) + " " + (dtBar == null));
Log((dts[2] == null) + " " + (dtChaz == null));
Log Output:
False 40
False 455
False 34
False True
False True
False True
Clearly I'm missing something important when working with reference type variables that I haven't been able to figure out. Why are my DataTable variables still null after the loop completes?