I have this code...
Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
// Create an instance of StreamReader to read from a file. // The using statement also closes the StreamReader. { // 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









Logged






