Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            PlayerCharachter[] players = new PlayerCharachter[3]
            {
                new PlayerCharachter {
                    Name = "Rehan"
                },
                new PlayerCharachter(), //Name = Null
                null                    //PlayerCharachter = null
            };

            //PlayerCharachter[] players = null;

            string p1 = players?[0]?.Name;
            string p2 = players?[1]?.Name;
            string p3 = players?[2]?.Name;

            //player.DaysSinceLastLogin = 42;

            //PlayerDisplayer.Write(players);

            //int days = player.DaysSinceLastLogin.Value;
            //int days = player ?. DaysSinceLastLogin ?? -1;

            //Console.WriteLine(days);

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public static void Write(PlayerCharachter player)
        {
            if (string.IsNullOrWhiteSpace(player.Name))
            {
                Console.WriteLine("Player is Null Or all Whitespaces");
            }
            else
            {
                Console.WriteLine(player.Name);
            }

            //int days = player.DaysSinceLastLogin.GetValueOrDefault(-1);

            //Conditional Operator -> ?:
            //int days = player.DaysSinceLastLogin.HasValue ? player.DaysSinceLastLogin.Value : -1 ;

            //Null Coalescing Operator -> ??
            int days = player.DaysSinceLastLogin ?? -1;

            //Null-Conditional Operator -> ?. ?[
            //int days = player?.DaysSinceLastLogin ?? -1;


            Console.WriteLine($"{days} days since last login");


            /*if(player.DaysSinceLastLogin.HasValue)
             * {
             *  Console.WriteLine(player.DaysSinceLastLogin.Value);
             * }
             * else
             * {
             *  Console.WriteLine("No Value for DaysSinceLastLoagin");
             * }*/

            if (player.DateOfBirth == null)
            {
                Console.WriteLine("No DOB has been specified.");
            }
            else
            {
                Console.WriteLine(player.DateOfBirth);
            }

            if (player.IsNoob == null)
            {
                Console.WriteLine("Player newbie Status is unknown.");
            }
            else if (player.IsNoob == true)
            {
                Console.WriteLine("Player is newbie");
            }
            else
            {
                Console.WriteLine("Player is experienced");
            }
        }