数组转换

       //获取ListBox中的要删除的角色
        ArrayList deleteRoleArray = new ArrayList();
        foreach (ListItem item in lst_RestRole.Items)
        {
            string newRoleName = item.Text;
            //判断是否是已经存在的
            foreach (string oldRoleName in oldRoleNames)
            {
                //如果是已经存在的,那么就放入要删除的ArrayList中
                if (oldRoleName == newRoleName)
                {
                    deleteRoleArray.Add(newRoleName);
                    break;
                }
            }
        }

        //把ArrayList转换成String[]
        string[] addRoleNames = (string[])roleArray.ToArray(typeof(string));

你可能感兴趣的:(数组)