c# - Cannot convert type string[] to string when value is assigned with number in [] -


Why is it not able to convert a string array to a string when a string is within the string array

code:

  int i; String [] file name; OpenFileDialog UnConvertedFilesList = New OpenFileDialog (); If (UnConvertedFilesList.ShowDialog () == DialogResult.OK) {foreach (string filename in UnConvertedFilesList.FileNames) {// right here file name [i] = filename; AudioFiles_listbox.Items.Add (file name); I ++; }} // if else {MessageBox.Show ("file does not exist"); }  

Edit: The file has been changed to the file name [i] = filename

Now it says, "Unassigned local variable 'filenames' For the purpose and for this I

defined at the top of their function.

There is an additional "s" your name here:

  // Here the file name must be [i] = filename;  

:

  // Right here file name [i] = filename;  

In addition, however, your The filename [] array is currently null . Once you fix your first problem you will have to struggle with it. My recommendation is to completely leave the array to use And just go directly to the audiofilebox. And once you do this, you can go right to the AddRange method of the listbox:

  AudioFiles_listbox.Items.AddRange (UnConvertedFilesList.FileNames);  

Comments