日期:2014-05-20  浏览次数:20856 次

求Lamba表达式

    class Program
    {
        static void Main(string[] args)
        {

        }

        // 求Lambda表达式,返回一个string类型。
        static string Cash()
        {
            string typeInfo = string.Empty;
            List<Product> pros = new List<Product>()
            {
                new Product(){TypeName="类型1",Type="1",Price=20},
                new Product(){TypeName="类型2",Type="1",Price=24},
                new Product(){TypeName="类型3",Type="2",Price=12}
            };
            foreach (var p in pros)
            {
                if (p.TypeName == "类型2")
                {
                    switch (p.Type)
                    {
                        case "1": typeInfo = "型号1"; break;
                        case "2": typeInfo = "型号2"; break;
                    }
                }
            }
            return typeInfo;
        }
    }
    struct Product
    {
        public string TypeName;
        public string Type;
        public double Price;
    }

------解决方案--------------------

  List<Product> pros = new List<Product>()
            {
                new Product(){TypeName="类型1",Type="1",Price=20},
                new Product(){TypeName="类型2",Type="1",Price=24},