示例#1
0
        /// <summary>
        /// Two differnet ways to handle a conversion from string to int.
        /// One using a try/catch block with an exception
        /// The other uses the out method which is NOT recommended.
        /// </summary>
        static void Main(string[] args)
        {
            var customer = new Customer(1);

            customer.Orders.Add(new Order());
            customer.Orders.Add(new Order());

            customer.Promote();

            Console.WriteLine(customer.Orders.Count);
            // best way
            try
            {
                var num = int.Parse("abc");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Conversion failed");
            }

            // this way is not recommended
            var result = int.TryParse("abc", out int number);

            if (result)
            {
                Console.WriteLine(number);
            }
            else
            {
                Console.WriteLine("Conversion failed");
            }
        }
示例#2
0
        private static void UseReadonly()
        {
            var customer = new Customer(1);

            customer.Orders.Add(new Order());
            customer.Orders.Add(new Order());

            customer.Promote();

            Console.WriteLine(customer.Orders.Count);
        }
示例#3
0
        static void Main(string[] args)
        {
            //var person = Person.Parse("Dharmendra");
            //person.Introduce("SS");

            //var customer = new Customer(1, "Dharmendra");
            //System.Console.WriteLine(customer.Name);
            //System.Console.WriteLine(customer.Id);
            //var order = new Order();
            //customer.Orders.Add(order);
            //System.Console.WriteLine(customer.Orders);

            //UseParams();
            //UsePoints();

            var customer = new Customer(1);

            customer.Orders.Add(new Order());
            customer.Orders.Add(new Order());
            Console.WriteLine(customer.Orders.Count);
            customer.Promote();
            Console.WriteLine(customer.Orders.Count);
        }