public static void Main(string[] args)
        {
            Console.WriteLine("Enter username:"******"Enter password:"******" {uname} is loggedin.");
                }
                else
                {
                    Console.WriteLine("the assword entered is incorrect");
                }
            }
            else
            {
                Console.WriteLine($" {uname} user not found.");
            }
            foreach (var kvp in LoginInfo)
            {
                Console.WriteLine($"{kvp.Key,10} {kvp.Value}");
            }

            string[] keys = new string[LoginInfo.Count];
            LoginInfo.Keys.CopyTo(keys, 0);
            for (int i = 0; i < keys.Length; i++)
            {
                Console.WriteLine($"{keys[i],10}");
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // Build a Login system using a dictionary.
            Console.Write("Username: "******"Password: "******"{username} is Logged On");
                }
                else
                {
                    Console.WriteLine($"The password entered is incorrect.");
                }
            }
            else
            {
                Console.WriteLine($"The username {username} is not found.");
            }
            Console.WriteLine("Another way");
            string correctPassword;

            if (LoginInfo.TryGetValue(username, out correctPassword))
            {
                if (correctPassword == password)
                {
                    Console.WriteLine($"{username} is Logged On");
                }
                else
                {
                    Console.WriteLine($"The password entered is incorrect.");
                }
            }
            else
            {
                Console.WriteLine($"The username {username} is not found.");
            }

            foreach (var kvp in LoginInfo)
            {
                Console.WriteLine($"{kvp.Key, 10} {kvp.Value}");
            }

            string[] keys = new string[LoginInfo.Keys.Count];
            LoginInfo.Keys.CopyTo(keys, 0);

            for (int i = 0; i < keys.Length; i++)
            {
                Console.WriteLine($"{keys[i], 10} {LoginInfo[keys[i]]}");
            }

            foreach (var key in LoginInfo.Keys)
            {
                Console.WriteLine($"{key,10} {LoginInfo[key]}");
            }
        }