using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LocalVariables
{
    class Examples16_21
    {
        public static void SomeStatements()
        {
            // Listing 2-16
            int a = 19;
            int b = 23;
            int c;
            c = a + b;
            Console.WriteLine(c);
        }

        public static void StatementsAndBlocks()
        {
            // Listing 2-17
            int a = 19;
            int b = 23;
            {
                int c;
                c = a + b;
                Console.WriteLine(c);
            }
        }

        public static void NestedExpressions()
        {
            // Listing 2-18
            double a = 1, b = 2.5, c = -3;
            double x = (-b + Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
            Console.WriteLine(x);
        }

        public static void MethodInvocationAsStatement()
        {
            // Listing 2-19
            Console.WriteLine("Witaj, świecie!");
            Console.WriteLine(12 + 30);
            Console.ReadKey();
            Math.Sqrt(4);
        }

        //// Kod umieszczony w komentarzach gdyż ilustruje błąd.
        //public static void BadStatements()
        //{
        //    // Listing 2-20
        //    Console.ReadKey().KeyChar + "!";
        //    Math.Sqrt(4) + 1; 
        //}

        public static void AssignmentsAsExpressions()
        {
            // Listing 2-21
            int number;
            Console.WriteLine(number = 123);
            Console.WriteLine(number);

            int x, y;
            x = y = 0;
            Console.WriteLine(x);
            Console.WriteLine(y);
        }
    }
}
