I'm getting stuck on the superhard c# assignment 6, but on the easy stuff.
I have this code...
but it isn't compiling due to 'Use of unassigned local variable fileContentsArrayList'. I know this is because there is a possibility that using() doesn't run and nothing gets put into it.
My problem is that I can't really add anything into the array to initialise it that isn't part of the streamreader. So how can I make sure that it initialises without breaking what the program does?
Many thanks
I have this code...
Code: (csharp)
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader(fileToEncryptText.Text))
{
// Temp string for lines
string line;
// Create an array list for the file contents
ArrayList fileContentsArrayList;
int i = 0;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
// Place line into array
fileContentsArrayList.Add(line);
// Increase [i]
i++;
//encryptOutputText.Text += encrypt.EncryptSingleLine(line) + "\r\n";
}
// Convert ArrayList into an Array
string[] fileContentsArray = (string[])fileContentsArrayList.ToArray();
}but it isn't compiling due to 'Use of unassigned local variable fileContentsArrayList'. I know this is because there is a possibility that using() doesn't run and nothing gets put into it.
My problem is that I can't really add anything into the array to initialise it that isn't part of the streamreader. So how can I make sure that it initialises without breaking what the program does?
Many thanks









