首先定义一类class User();然后在一个ArraryList中放入多个User对象;现在在建一个User数组,把ArraryList中的元素转移到User数组中!!
ArraryList aList=new ArraryList();
for(){
 aList.add();
}User[] u=aList.ToArrary() as User[];   //这样是错误的!!,正确该这样写!!

解决方案 »

  1.   

    object[] oList = aList.ToArray();用到其中元素的时候,再强制转化。
      

  2.   

    using System;
    using System.Collections;public class MyClass
    {
    public static void Main()
    {
    ArrayList tempAL = new ArrayList();

    A a1 = new A();
    a1.S = "1";
    tempAL.Add(a1);
    A a2 = new A();
    a2.S = "2";
    tempAL.Add(a2);

    A[] a = new A[tempAL.Count];
    tempAL.CopyTo(a);

    for( int i = 0;i < a.Length;i++)
    {
    Console.WriteLine(a[i].S);
    }
    Console.ReadLine();
    }

    public struct A
    {
    public String S;
    }

    }
      

  3.   

    从新看这个问题!!!:
    stream s=new stream();
    byte b[]=s.ToArray();  //这是正确的!!ArraryList aList=new ArraryList();
    for(){
     aList.add();
    }User[] u=aList.ToArrary();//这样是错误的!!,对比一下,,为什么???