Array和ArrayList互相转换

class Order
{
public string orderId;
public string orderName;
public decimal orderPrice;

}

public class ConvertToArrayList
{
//方法一
public ArrayList ArrayToArrayList(Order[] orders)
{
ArrayList al = ArrayList.Adapter(orders);
return al;
}
//方法二
public ArrayList ArrayToArrayList2(Order[] orders)
{
ArrayList al = new ArrayList();
foreach (Order or in orders)
{
al.Add(or);
}
return al;
}

public Array ArrayListToArray(ArrayList al)
{
Order[] order = (Order[])al.ToArray(typeof(Order));
return order;
}
}

Array和ArrayList互相转换

上一篇:test maekdown 2


下一篇:final方法,abstract方法和abstract类,native方法