LINQ 查询

    http://www.icbc.com.cn/ICBCDynamicSite/Charts/AccGold.aspx?dataType=0&dataId=903&picType=3
class Program
    {
        static void Main(string[] args)
        {
            List products = GetProductList();
            var soldOutProducts =
                from prod in products
                where prod.UnitsInStock == 0
                select prod;

            Console.WriteLine("售出产品:");
            foreach (var product in soldOutProducts)
            {
                Console.WriteLine("{0} 已经卖完了!", product.ProductName);
            }
            var inventory =
                from prodInvent in products
                where prodInvent.UnitsInStock > 0
                select prodInvent;
            foreach (var productInvent in inventory)
            {
                Console.WriteLine("{0} 库存{1}!",productInvent.ProductName, productInvent.UnitsInStock);
            }
            Console.ReadLine();
        }
        public static List GetProductList()
        {
            List list = new List();
            Product model = new Product();
            model.ProductName = "秋葵";
            model.UnitsInStock=0;
            Product model2 = new Product();
            model2.ProductName = "羊肉";
            model2.UnitsInStock = 1;
            list.Add(model);
            list.Add(model2);
            return list;
        }
    }
    public class Product 
    {
        private string _ProductName;
        /// 
        /// 产品名称
        /// 
        public string ProductName
        {
            get { return _ProductName; }
            set { _ProductName = value; }
        }
        private int _UnitsInStock;
        /// 
        /// 库存量
        /// 
        public int UnitsInStock
        {
            get { return _UnitsInStock; }
            set { _UnitsInStock = value; }
        }
    }

你可能感兴趣的:(LINQ 查询)