Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
56 views
in Technique[技术] by (71.8m points)

c# - Problem to use a list instead of an array

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...