コード例 #1
0
ファイル: Program.cs プロジェクト: LindseyNastos/Labs
            static void Main(string[] args)
            {
                var product1 = new Product
                {
                    Price = 3m
                };
                var product2 = product1;
                product2.Price = 5m;
                //This is a class so they're reference types
                //They refer to the same thing, so it changed the data in the class

                Console.WriteLine(product1.Price);
                Console.ReadLine();
            }
コード例 #2
0
ファイル: Program.cs プロジェクト: LindseyNastos/Labs
            static void Main(string[] args)
            {
                var product1 = new Product
                {
                    Price = 3m
                };

                var product2 = new Product
                {
                    Price = 3m
                };

                Console.WriteLine(product1 == product2);
                Console.ReadLine();
            }
コード例 #3
0
ファイル: Program.cs プロジェクト: LindseyNastos/Labs
        static void Main(string[] args)
        {
            var product1 = new Product();
            //creates new product (calling a method on the class)
            product1.Name = "Tesla";
            product1.Price = 98779.09809m;

            //OR

            var eggs = new Product
            {
                Name = "Eggs",
                Price = 78798.99m
            };

            eggs.Save();

            var total = eggs.CalculateTotal(taxRate:0.5m, discount:2.00m); 
            //(0.08, 2.00m) are argument passed to parameter
            //optional labels on arguments. not required, but helpful for clarity/readability
            //var total = eggs.CalculateTotal(); ==> will use defaults
            //var total = eggs.CalculateTotal(discount:2.00m) ==> overrides default

            //OLD WAY: var message = "It costs " + total + " which is cheap!";

            var message = String.Format("It costs {0:c} which is {1}!", total, "great");
            //Console.WriteLine("It costs {0:c} which is {1}!", total, "great"); works too
            //{placenumber: } 

            Console.WriteLine(message);
            Console.ReadLine();

            var message1 = eggs.FormatStuff("hello", "world", "how", "are", "you", "today?");
            //if creating shopping cart - to add things to cart
            //use when you dont know how many parameters
            Console.WriteLine(message1);
            Console.ReadLine();


            Console.WriteLine(total.ToString("c"));
            Console.ReadLine();

            var total1 = eggs.CalculateTotal();
            Console.ReadLine();

            var total2 = eggs.CalculateTotal(0.09m);
            Console.ReadLine();

            var total3 = eggs.CalculateTotal(0.09m, 0.25m);
            Console.ReadLine();



            var customer1 = new Customer
            {
                LastName = "Smith"
            };

            var customer2 = new Customer("Lindsey", "Nastos");

            Console.WriteLine(customer1.LastName);
            Console.ReadLine();


            var customer1 = new Customer
            {
                FirstName = "Lindsey",
                LastName = "Nastos",
                BillingAddress =
                {
                    Street = "Main",
                    City = "Seattle",
                    ZipCode = "99999"
                },
                ShippingAddress =
                {
                    Street = "Broadway",
                    City = "Kirkland",
                    ZipCode = "88888"
                }

            };


            var product2 = new Product
            {
                Price = 3.44m
            };

            Console.WriteLine(Product.GetTax(344.23));
            Console.ReadLine();

            var car = new CertifiedUsedCar
            {
                   CertifiedRanking = 7,
                   Make = "Tesla",
                   Model = "Tesla S"

            };

            car.Honk();

            var bear = new Bear
            {
                Name = "Smokey"
            };

            var eagle = new Eagle
            {
                Name = "Sam"
            };



            AnimalUtility.DoSomething(bear);
            AnimalUtility.DoSomething(eagle);

            Console.ReadLine();

        }