Greetings to all,
Wondering if someone can help me with a basic VS C# problem? Help much appreciated.
I can read my plain text file into an array and display one line at a time on the console with this code.
int indexInt = 0;
string fileString = "";
string[] array = new string[12]
StreamReader fileReader = new StreamReader("C:\\text.txt");
while(fileString != null)
{
fileString = fileReader.ReadLine();
if(fileString != null)
{
array[indexInt++] = fileString;
}
}
foreach(string aString in array)
{
Console.WriteLine(aString);
Console.ReadLine();
}
Basic reading of a text file into an array and reading the array to the console.
Where I run into trouble is when my array is an array of a Struct.
If I declare the following struct:
public Struct Text
{
public string someText;
}
And an array of the struct.
public Text[] structArray = new Text[12];
I do not know how to reference structArray properly in order to load it from the file.
'structArray[ indexInt++].someText
' used in the above code gives 'object reference required' error.