博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

List.FindAll===>toArray()

Posted on 2011-04-03 23:31  moss_tan_jun  阅读(1664)  评论(1编辑  收藏  举报

 

 

 public class OrdersType
    {
        private string _OrderNum;

        public string OrderNum
        {
            get { return _OrderNum; }
            set { _OrderNum = value; }
        }
        private string _Invs_num;

        public string Invs_num
        {
            get { return _Invs_num; }
            set { _Invs_num = value; }
        }
        private string _CountryCode;

        public string CountryCode
        {
            get { return _CountryCode; }
            set { _CountryCode = value; }
        }
        private Items[] _ItemList;

        public Items[] ItemList
        {
            get { return _ItemList; }
            set { _ItemList = value; }
        }

        private GoodsInfoType[] _GoodsInfoType;

        public GoodsInfoType[] GoodsInfoType
        {
            get { return _GoodsInfoType; }
            set { _GoodsInfoType = value; }
        }
    }

 

-----------------------------------------------------------------------------------------------------

  private void ListTest(List<GoodsInfoType> goods)
        {
            List<GoodsInfoType> glist = new List<GoodsInfoType>();
            string TypeId = string.Empty;
            List<string> strId = new List<string>();

            OrdersType order = new OrdersType();
            order.Invs_num = "123456";

            order.OrderNum = "MW1234848";
            order.CountryCode = "CN";


            foreach (GoodsInfoType good in goods)
            {
                TypeId = good.GoodsTypeID1;

                if (strId.Contains(TypeId))
                {
                    continue;
                }
               
                glist = goods.FindAll(p =>
                {
                    if (p.GoodsTypeID1 == TypeId)
                    {
                      
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                });

                order.GoodsInfoType = glist.ToArray();
                strId.Add(TypeId);

            }
        }