c# - 使用列表而不是数组的问题
问题描述
在这里,我正在尝试做一个音乐媒体播放器。我做得很好,感谢一个普通的数组。但是,当我尝试使用无法做到的列表时。
stringName.Add(openFileDialog1.SafeFileNames);
第一个问题是在这一行中,我无法将字符串数组转换为字符串。所以我可以在没有它的情况下使用另一种方法,但它只给我列表中的一个声音,不可能得到更多。我需要加载更多歌曲。
这是我的代码:
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]);
}
}
}
这里的目标是把我的名字歌曲列表而不是我的列表,并在我的 listbox1 中显示这个列表。你有什么主意吗 ?我是 C# 新手,我想改进我的代码以便更好地理解和升级。非常感谢您的帮助。或者也许它是唯一的解决方案?
解决方案
推荐阅读
- python - 在 python 环境中从 Dialogflow 中获取 Intents、Entities 和训练数据
- python - TBSelenium:Tor 页面立即关闭
- python - 在特定对象级别将 pandas DataFrame 中的列添加到深度嵌套的 JSON 中
- ssl - 需要使用开放 SSL 创建证书
- javascript - 修复 CSS 悬停时的按钮样式?
- sql - 在其中一列中将英亩转换为平方英尺
- elasticsearch - 严格使用 ElasticSearch 映射
- python - 如何在 Lynx 等 webbrowser 或 python webbrowser 上添加 xmpp 或矩阵协议?
- html - 如何从 ExpressJS 路由保存呈现的 html 视图文件
- php - 在布尔值中调用成员函数 fetch() 时出错