tags:

views:

36

answers:

2

Why does it complain about it not being able to convert a string array to a string when the values are strings within a string array

Code:

 int i;
            string[] Filenames;

            OpenFileDialog UnConvertedFilesList = new OpenFileDialog();
            if (UnConvertedFilesList.ShowDialog() == DialogResult.OK)
            {

                foreach (string FileName in UnConvertedFilesList.FileNames)
                {

                    //Right Here
                    Filenames[i] = Filenames;
                    AudioFiles_listbox.Items.Add(FileName);
                    i++;
                }

            }//if
            else
            {
                MessageBox.Show("File does not exist");
            }

edit: that line to Changed Filenames[i] = FileName

Now it says "Use of unassigned local variable 'Filenames' and same thing for i

Their defined at the top of the function.

+4  A: 

You have an extra "s" on your name there:

//Right Here
Filenames[i] = Filenames;

should be:

//Right Here
Filenames[i] = FileName;

More than that, though, your Filenames[] array is currently null. Once you fix your first problem you'll have that to contend with. My recommendation there is to skip using the array entirely and just go directly to the AudioFiles_listbox. And once you do that, you can go right for the Listbox's AddRange method.

Joel Coehoorn
It's actually FileName - note the capital N. But he should figure that out. Also i is never initialised. He needs int i=0. Cheers +1
Marko
A: 

Hey,

"Use of unassigned" means that you aren't using it anywhere within that method or segment of code... your assignment is now OK, but it's not being used.

HTH.

Brian