I have this code...
- // 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
- // Increase [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?