Esempio n. 1
0
        static void Main(string[] args)
        {
            //Counting Words in a String
            Console.WriteLine(Counter.CountWords("Hello World!"));
            Console.WriteLine(Counter.CountWords("The Cat in the Hat"));

            //Extension methods
            Console.Write("The quick brown fox".WordCount());
            foreach (var word in "The quick brown fox jumps over the lazy dog".GetFirstWords(4))
            {
                Console.Write(word);
            }


            //Car Class: How interfaces work
            var car = new CertifiedUsedCar {
                VIN            = "XXXXXXXX1234xxx",
                Model          = "BMW",
                Price          = 50000m,
                Miles          = 4000,
                WarrantyMonths = 12
            };

            var usedCar = new UsedCar {
                VIN   = "XXXX00X00",
                Price = 10000m
            };
            var tax = usedCar.CalculateTax();

            var inventory = new Car[] {
                new UsedCar {
                    VIN = "78YSDDFSD45", Price = 17000m
                },
                new CertifiedUsedCar {
                    VIN = "888SDDFSD45", Price = 17000m
                },
                new NewCar {
                    VIN = "YIUIU66II77", Price = 44000m
                },
                new UsedCar {
                    VIN = "3NBMM99887", Price = 12000m
                },
                new UsedCar {
                    VIN = "55555OOOOOP", Price = 11000m
                }
            };

            var total = 0m;

            foreach (var usedcar in inventory)
            {
                total += usedcar.Price;
            }
            Console.WriteLine("Total inventory value: " + total.ToString("c"));

            Console.ReadLine();
        }
Esempio n. 2
0
        public void Run()
        {
            var text         = ReadText();
            var stoppedWords = fs.ReadStoppedWords();

            var counter = new Counter();

            var count = counter.CountWords(text, stoppedWords);

            shell.Write(count);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            //gets word count of first sentence
            var words = Counter.CountWords("Hello World!");

            Console.WriteLine("Number of words is " + words);

            //gets word count of second sentence
            words = Counter.CountWords("The Cat in the Hat");
            Console.WriteLine("Number of words is " + words);

            Console.ReadLine();
        }