如题~~~我想传入web service 一个arraylist, 但是老是提示说arraylist 不能转换成object []web services 
  public DataSet Shopingcart(ArrayList Booklist)
    {
          string cn = "Data Source=.;Initial Catalog=951;User ID=sa;Password=0591245";
        SqlConnection conn = new SqlConnection(cn);
        conn.Open();
        DataSet ds = new DataSet();
        foreach (string s in Booklist)
        {
            string sql = string.Format("select BookNo,BookName,Prices from BookInfo WHERE BookNo='{0}'", Booklist[0]);
            SqlCommand cmd = new SqlCommand(sql, conn);            //ds.Tables.Add(newDT);
            SqlDataAdapter da = new SqlDataAdapter(sql, conn);
            da.Fill(ds);
        }
        return ds;
}网站上  protected void Page_Load(object sender, EventArgs e)
    {
           object[] Bl = (ArrayList )Session["Booklist"];
              BookSearch.Service Shopcart = new BookSearch.Service();        
        
        ds = Shopcart.Shopingcart(Bl);
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();               
        
    }

解决方案 »

  1.   


    这样也行?直接用Array B1=(ArrayList )Session["Booklist"];
      

  2.   

    Array B1=(ArrayList )Session["Booklist"]; 这样就可以了啊,何必再转换呢?
      

  3.   

    其实调用一个函数就可以了,楼主你想复杂了!
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using System.Collections;namespace ConsoleApplication1
    {
        class Program
        {
            public Program()
            {
                ArrayList al = new ArrayList();
                al.Add(1);
                al.Add(2);
                //此时al中有两个元素            //直接调用ToArray()函数进行转换,使用save接收
                object[] save = al.ToArray();
            }        static void Main()
            {
                Program p1 = new Program();            Console.ReadLine();
            }
        }}
      

  4.   

    ArrayList 是一个对象
    Ojbect[] 是一个数组
      

  5.   

    protected void Page_Load(object sender, EventArgs e)
    {
      ArrayList Bl = (ArrayList)Session["Booklist"];
      BookSearch.Service Shopcart = new BookSearch.Service();
      ds = Shopcart.Shopingcart(Bl);
      GridView1.DataSource = ds.Tables[0];
      GridView1.DataBind();
    }
      

  6.   

    如果你一定要转换为 object[],就用 ToArray():
    object[] Bl = ((ArrayList)Session["Booklist"]).ToArray();
      

  7.   

    Array B1=(ArrayList )Session["Booklist"];
    这个直接用的话,系统报错的,要不然我也不会去想着转了
      

  8.   

    如果ArrayList对象是在Session里边你可以先把ArrayList提取出来,然后再将ArrayList转换成object[],楼主你没有把ArrayList对象提取出来罢了!