i am making mp3 player using c# but i am sufferring from this error
"Cannot implicitly convert type 'string' to 'string[]".
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
string[] f, p;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
f = openFileDialog1.SafeFileName;
p = openFileDialog1.FileName;
for (int i = 0; i < f.Length; i++)
{
listBox1.Items.Add(f[i]);
}
foreach(string d in open.FileNames)
{
listBox1.Items.Add(d);
}
}
}
private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
axWindowsMediaPlayer1.URL = p[listBox1.SelectedIndex];
}
}
}
It looks like you're trying to handle the user opening multiple files. In that case, use FileDialog.FileNames
instead of FileName
. Ditto SafeFileNames
.
(I would also strongly recommend renaming the variables so their names are meaningful - f
and p
don't tell you anything about them.)
See more on this question at Stackoverflow