コード例 #1
0
        //c# 1
        public static void QueryVersionOne()
        {
            ArrayList products = ProductVersionOne.GetSomeProduct();

            foreach (ProductVersionOne p in products)
            {
                if (p.Price > 10m)
                {
                    Console.WriteLine(p);
                }
            }
        }
コード例 #2
0
ファイル: TestCases.cs プロジェクト: luqc123/CSharpTest
        public static void TestClassFeatures()
        {
            ArrayList product1 = ProductVersionOne.GetSomeProduct();

            product1.Sort(new ProductComparerVersionOne());
            foreach (var t in product1)
            {
                Console.WriteLine(t);
            }

            //generic no boxing
            List <ProductVersionTwo> product2 = ProductVersionTwo.GetSomeProduct();

            //product2.Sort(new ProductComparerVersionTwo());
            product2.Sort(delegate(ProductVersionTwo x, ProductVersionTwo y) { return(x.Name.CompareTo(y.Name)); });
            foreach (var item in product2)
            {
                Console.WriteLine(item);
            }

            var product3 = ProductVersionThree.GetSomeProduct();

            //delegate version1
            product3.Sort(delegate(ProductVersionThree x, ProductVersionThree y)
            {
                return(x.Name.CompareTo(y.Name));
            });
            product3.Sort((x, y) => x.Name.CompareTo(y.Name));
            foreach (var p in product3)
            {
                Console.WriteLine(p);
            }

            var product4 = ProductVersionFour.GetSomeProduct();

            foreach (var p in product4.OrderBy(p => p.Name))
            {
                Console.WriteLine(p);
            }

            foreach (var p in product4)
            {
                Console.WriteLine(p);
            }
        }