So I am trying to create an array of structures for exporting data from a database to a formatted file for later import to another database and/or reports.
I know what a Null Reference Exception is, based upon the reading I had done in the link I provided in my comments below, I believed that I had hit an edge case that I needed clarification on, only to learn the NEW keyword while making me an array like I wanted, didn't initiate each class within the array an assumption I made about .NET which of course was faulty. While Yes this question has to do with a Null Reference Exception I'm not asking what a Null Reference Exception is.
This is My struct
public class udtExportType
{
public int intPatientID = 0;
public string strFirstName = string.Empty;
public string strMiddleName = string.Empty;
public string strLastName = string.Empty;
}
Here is where I initialize the structure
// Create an array of structures based upon the length of the Patient Data Array
udtExportData = new udtExportType[intRecordCount];
//A Professional Masseuse used to massage data from the VPatientExportData View.
PatientDataMasseuse(strPatientData, ref udtExportData);
Here is where I try adding the Data from the PatientDataMasseuse
// Add To Structure
udtExportdata[intIndex].strFirstName = strPatientData[intIndex].Substring(intIDIndex, (intFullNameIndex - intIDIndex));
but on the above line I get a Null reference exception, how is this possible? I used the new keyword when I initialize and I passed it by ref. I even tried inserting data before it went into the PatientDataMasseuse procedure as a result, and I got the same error. I read some questions on this site, and hunted around MSDN and I see no difference between what I have typed versus anyone else.
Help is much appreciated.
* EDIT *
I assumed .NET would do this for me with the new keyword but it turns out you have to do it manually for each element in the array
for(intIndex = 0; intIndex < Length(); intIndex += 1)
{
udtExportData[intIndex] = new udtExportType();
}