here i am trying to do a music media player. I do it great thanks a normal array. However when i am trying to use a list impossible to do it.
stringName.Add(openFileDialog1.SafeFileNames);
the first problem is in this line, I can't convert a string array to string. so i can use the other method without it but it give me only one sound from my list impossible to get more. And I need to load more songs.
Here my code:
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
//--------------------Thanks to array work perfectly
//arraylist1 = openFileDialog1.SafeFileNames;
//a2 = openFileDialog1.FileNames;
//for (int i = 0; i < arraylist1.Length; i++)
//{
// listBox1.Items.Add(arraylist1[i]);
//}
//----------------------- with lists it doesn't work-------------------------
stringName.Add(openFileDialog1.SafeFileName);
MessageBox.Show(stringName.Count.ToString());
for (int i = 0; i < stringName.Count; i++)
{
listBox1.Items.Add(stringName[i]);
}
}
}
the goal here is to put my list of name songs instead my list and show this list in my listbox1. Do you have any Idea ? I am new in c# i want to improve my code for a better understanding and upgrade. Thank you very much for your help. Or maybe its the only solution ?
question from:https://stackoverflow.com/questions/65939033/problem-to-use-a-list-instead-of-an-array