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

namespace DataAndOperators
{
    class Examples39_46
    {
        public static void ConditionalAnd()
        {
            string s = null;

            // Listing 2-39
            if (s != null && s.Length > 10)
            {
                Console.WriteLine("phi");
            }
        }

        public static void Conditional()
        {
            int x = 42;
            int y = 123;

            // Listing 2-40
            int max = (x > y) ? x : y;

            Console.WriteLine(max);
            // choć każdy by zapewne użył poniższego wywołania:
            Console.WriteLine(Math.Max(x, y));

            string s = null;

            // Listing 2-41
            int characterCount = s == null ? 0 : s.Length;

            Console.WriteLine(characterCount);

            // Listing 2-42
            string neverNull = s ?? "";

            Console.WriteLine(neverNull.Length);

            bool gateOpen = false;
            const double MaxVolume = 1.0;
            TimeSpan FadeDuration = TimeSpan.FromSeconds(4);

            // Listing 2-43
            FadeVolume(gateOpen ? MaxVolume : 0.0, FadeDuration, FadeCurve.Linear);

            // Listing 2-44
            double targetVolume;
            if (gateOpen)
            {
                targetVolume = MaxVolume;
            }
            else
            {
                targetVolume = 0.0;
            }
            FadeVolume(targetVolume, FadeDuration, FadeCurve.Linear); 

        }

        private static void FadeVolume(double vol, TimeSpan duration, FadeCurve type)
        {
        }

        // Typ utworzony na potrzeby przykładu.
        enum FadeCurve
        {
            Linear
        }

        public static void CompoundAssignment()
        {
            int x = 0;

            // Listing 2-45
            x = x + 1;

            Console.WriteLine(x);

            // Listing 2-46
            x += 1;

            Console.WriteLine(x);
        }
    }
}
