偶在数组 playList中存放了播放列表,想通过按钮删除实现清空playList中的数据:
private void menuItemDelAll_Click(object sender, System.EventArgs e)
{
listBox1.Items.Clear();
for(int i = 0;i < playList.Length; i ++ )

playList[i] = '';
}
结果系统提示错误:“空字符”
!!>_<
请问应该怎样实现清空playList数组?

解决方案 »

  1.   

    字符串吧,不是用'',用""或者null
      

  2.   

    private void menuItemDelAll_Click(object sender, System.EventArgs e)
    {
      listBox1.Items.Clear();
      playList.Clear();
    }
      

  3.   

    salmon230:
    ^-^thanks  ~~
      

  4.   

    playList.Clear()
    调试发生错误: 重载“Clear”方法未获取“0”参数
    ??
      

  5.   

    你的 playList 是什么类型的?
      

  6.   

    private void menuItemDelAll_Click(object sender, System.EventArgs e)
    {
      listBox1.Items.Clear();
      playList.Length = 0;
    }
      

  7.   

    // 错了,应该是:private void menuItemDelAll_Click(object sender, System.EventArgs e)
    {
      listBox1.Items.Clear();
      playList = new string [0];
    }
      

  8.   

    OK  ~`
    我想知道playList = new string [0];跟playList[i] = "";有区别吗?
    在清除playList中的文件路径后,我得要把 songindex (songindex记录歌曲总数) 赋值为0.
    偶分别用两种方法调试,结果用playList = new string [0]时出现错误,当清空后再重新添加文件时,出现错误:“索引超出了数组界限”
    方法一:(失败~_~!)
    private void menuItemDelAll_Click(object sender, System.EventArgs e)
    {
    listBox1.Items.Clear();
    playList = new string [0];
    songindex = 0;
    }
    方法二:(成功^_^~)
    private void menuItemDelAll_Click(object sender, System.EventArgs e)
                      {
    listBox1.Items.Clear();
    for(int i = 0;i < playList.Length; i ++ )

        playList[i] = "";

    songindex = 0;

    }
      

  9.   

    如果只是string的话
    Array.Clear(playList)
    上面有人说过了
      

  10.   

    Array.Clear(playList,0,playList.Length - 1)
      

  11.   

    hoho...知道了
    第一次发帖就有那么多人回复~~感动、落泪
    多谢了~~