Exemplo n.º 1
0
        private static void serializingXml()
        {
            Student s = new Student();

            s.Name    = MyConsole.getString("Enter the name");
            s.Address = MyConsole.getString("Enter the address");
            s.Phone   = MyConsole.getNumber("Enter the landline Phone no");
            FileStream    fs = new FileStream("Data.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            XmlSerializer sl = new XmlSerializer(typeof(Student));

            sl.Serialize(fs, s);
            fs.Flush();
            fs.Close();
        }
Exemplo n.º 2
0
        private static void DictionaryExample()
        {
            Dictionary <string, string> users = new Dictionary <string, string>();
            bool adding = true;

            do
            {
Tryagain:
                string username = MyConsole.getString("Enter a Username for UR login");
                string pwd = MyConsole.getString("Enter the Password");
                if (users.ContainsKey(username))
                {
                    Console.WriteLine("User already exists\nPlease try again");
                    goto Tryagain;
                }
                else
                {
                    users[username] = pwd;
                }
                string choice = MyConsole.getString("Press A to add or any key to leave");
                adding = choice.ToUpper() == "A" ? true : false;
            } while (adding);

            Console.WriteLine("Lets allow the user to log...");
            string uname = MyConsole.getString("Enter a Username for UR login");
            string upwd  = MyConsole.getString("Enter the Password");

            if (users.ContainsKey(uname))
            {
                if (users[uname] == upwd)
                {
                    Console.WriteLine("Welcome user!!!!");
                }
                else
                {
                    Console.WriteLine("Password is wrong!!!!");
                }
            }
            else
            {
                Console.WriteLine("user name is wrong!!!!");
            }
        }
Exemplo n.º 3
0
        private static void QueueExample()
        {
            Queue <string> recentItems = new Queue <string>();

            do
            {
                string item = MyConsole.getString("Enter the Item to view");
                if (recentItems.Count == 3)
                {
                    recentItems.Dequeue();//Removes the first item in the queue.
                }
                recentItems.Enqueue(item);
                Console.WriteLine("Ur recently viewed items:");
                var iterator = recentItems.Reverse();
                foreach (string obj in iterator)
                {
                    Console.WriteLine(obj);
                }
            } while (true);
        }